How to remove PSMShadowUser User and Profile in bulk with Power-Shell Script

How to remove PSMShadowUser User and Profile in bulk with Power-Shell Script

105
Created On 11/10/26 10:59 AM - Last Modified 11/10/26 16:11 PM


Objective


In some situations  it is required to remove all PSMShadowUsers and their profiles  from the PSM server, The User and Profiles will be recreated upon next logon.
The manual steps can be found  under Article 000007570.

In case customer has a large amount PSMShadowUser to remove on multiple servers  , it would be a time consuming  task.

Below is how it can be done  in bulk using PowerShell script.


 


Environment


10.0;10.1;10.2;10.3;10.4;10.5;10.6;10.7;10.8;10.9;10.10;11.1;11

Procedure


Step 1:
Get-WmiObject Win32_UserAccount -Filter "LocalAccount='True' And NAme LIKE 'PSM-%'" |Out-File -FilePath c:\temp\deleteShadowuser.txt| % {Invoke-Command -ScriptBlock {net user $_.Name /delete}}
# customer is required to create a c:\temp\ folder before running above script
# There are 3 steps included :  
#1) retrieve all account starts with 'PSM-" from local computer ,
#2) store the list to c:\temp\deleteShadowuser.txt
# 3)delete all local accounts found from step 1)


Step 2:
Get-CimInstance -ComputerName localhost -Class Win32_UserProfile | Where-Object { $_.LocalPath.split('\')[-1] -like 'PSM-*' } | Remove-CimInstance
# this script removes all user profiles includes the  C:\Users\PSM-xxxxxxxxxxxxxx folders as well as the #correspondent registry under 
# HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList

 


Actions
  • Print
  • Copy Link

    https://knowledgebase.paloaltonetworks.com/KCSArticleDetail?id=kA1hj0000001bQXCAY&lang=en_US&refURL=http%3A%2F%2Fknowledgebase.paloaltonetworks.com%2FKCSArticleDetail