Skip to main content

User Profile Removal

Summary

This script removes a user profile from an endpoint. It prompts the user for confirmation (y or n) and requests the username to be removed. Note that the script cannot remove the user profile of a currently logged-in user. (See the Agent Procedure Log below for an example of this.)

Example Agent Procedure Log

TimeActionResultUser
8:41:43 am 1-Mar-23User Profile RemovalSuccess THENdan.hicks
8:41:43 am 1-Mar-23User Profile Removal-0004ERROR: 2023-03-01 08:41:41 An error occurred when attempting to remove the user profile. Error: The process cannot access the file because it is being used by another process.dan.hicks
8:41:43 am 1-Mar-23User Profile Removal-0002Log: 2023-03-01 08:41:33 INIT ----------------------------------------------- 2023-03-01 08:41:33 INIT Remove-UserProfile 2023-03-01 08:41:33 INIT System: DEV 2023-03-01 08:41:33 INIT User: DEV$ 2023-03-01 08:41:33 INIT OS Bitness: AMD64 2023-03-01 08:41:33 INIT PowerShell Bitness: 64 2023-03-01 08:41:33 INIT PowerShell Version: 5 2023-03-01 08:41:33 INIT ----------------------------------------------- 2023-03-01 08:41:33 LOG Checking if 'DEV//test1' is a local account. 2023-03-01 08:41:35 LOG Local account: True 2023-03-01 08:41:35 LOG Gathering profile data. 2023-03-01 08:41:35 LOG Removing local user account 'test1' 2023-03-01 08:41:35 LOG Removed local user account 'test1' 2023-03-01 08:41:35 LOG Beginning processing of profile 'C://Users//test1'. 2023-03-01 08:41:40 LOG Checking for profile CIM instance. 2023-03-01 08:41:41 LOG Removing profile CIM instance. 2023-03-01 08:41:41 ...dan.hicks
8:41:42 am 1-Mar-23User Profile RemovalRaw PS1 Data:dan.hicks
8:41:42 am 1-Mar-23Execute Powershell Command (64-bit, Run As System)Success THENdan.hicks
8:41:42 am 1-Mar-23Execute Powershell Command (64-bit, Run As System)-0016Powershell command complete. Results returned to global variable #global:psresult# and saved in Agent's Documents tab of server.dan.hicks
8:41:28 am 1-Mar-23Execute Powershell Command (64-bit, Run As System)-0011Executing 64-bit Powershell command as System: "" -command "%ProgramData%//_automation//AgentProcedure//UserProfileRemoval//Remove-UserProfile.ps1 -Username test1" >"c://kworking//psoutputtmp.txt"dan.hicks
8:41:28 am 1-Mar-23Execute Powershell Command (64-bit, Run As System)-0013Sending output to global variable.dan.hicks
8:41:28 am 1-Mar-23Execute Powershell Command (64-bit, Run As System)-0008Custom commands detected as %ProgramData%//_automation//AgentProcedure//UserProfileRemoval//Remove-UserProfile.ps1 -Username test1dan.hicks
8:41:28 am 1-Mar-23Execute Powershell Command (64-bit, Run As System)-0003No Powershell file variable detected.dan.hicks
8:41:22 am 1-Mar-23Execute Powershell Command (64-bit, Run As System)-0002Powershell is present.dan.hicks
8:41:12 am 1-Mar-23Execute Powershell CommandSuccess THENdan.hicks
8:41:12 am 1-Mar-23Execute Powershell Command-0011Powershell command completed!dan.hicks
8:41:09 am 1-Mar-23Execute Powershell Command-0011Executing powershell "" -Command "New-Item -Type Directory -Path $env:ProgramData//_automation//AgentProcedure -name UserProfileRemoval" ""dan.hicks
8:41:09 am 1-Mar-23Execute Powershell Command-0010Not sending output to variable.dan.hicks
8:41:09 am 1-Mar-23Execute Powershell Command-0008New command variable is: -Command "New-Item -Type Directory -Path $env:ProgramData//_automation//AgentProcedure -name UserProfileRemoval"dan.hicks
8:41:09 am 1-Mar-23Execute Powershell Command-0008Custom commands detected as New-Item -Type Directory -Path $env:ProgramData//_automation//AgentProcedure -name UserProfileRemovaldan.hicks
8:41:03 am 1-Mar-23Execute Powershell Command-0002Powershell is present.dan.hicks
8:40:55 am 1-Mar-23Run Now - User Profile RemovalAdmin dan.hicks scheduled procedure Run Now - User Profile Removal to run at Mar 1 2023 8:40AM

Dependencies

EPM - Accounts - Agnostic - Remove-UserProfile

Output

AP Log