Created
March 1, 2020 00:34
-
-
Save PSingletary/26a5f2413036d03f8491c0812e913427 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Invoke-Command -ComputerName $WBComputers.Name -ScriptBlock { | |
| $GoneUsers = Get-WmiObject -Class win32_userprofile | | |
| Select-Object -Property *, @{ | |
| NAME = 'user' | |
| EXPRESSION = { | |
| ((New-Object -TypeName System.Security.Principal.SecurityIdentifier -ArgumentList ($_.SID)).Translate([System.Security.Principal.NTAccount])).Value | |
| } | |
| } | | |
| Where-Object -FilterScript { | |
| $_.User -eq $null | |
| } | |
| $GoneUsers | ForEach-Object -Process { | |
| if ($_.LocalPath) | |
| { | |
| $prof = Get-WmiObject -Class win32_userprofile -Filter "SID='$($_.SID)'" | |
| $prof.delete() | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment