Hi All,
I have script for Account unknown user profile deletion but i need to login each and every for this clean up activity, So i want to run this script from my local client OS or my VDI to clear on all remote servers at a time and i want to know the user profile last login and log out time with date
$Computer = "DESKTOP-T20064S"
$Output = "C:\Temp\AccountUnknownProfiles\CleanUPProfiles.xls"
Get-CimInstance win32_userprofile | foreach {
Get-wmiobject win32_userprofile -Computername DESKTOP-T20064S | Select PSComputerName,LocalPath,SID,LastUseTime | Export-Csv -Path $output | format-list
$u = $_
try {
$objSID = New-Object System.Security.Principal.SecurityIdentifier($U.sid) -ErrorAction stop
$objUser = $objSID.Translate( [System.Security.Principal.NTAccount])
"User={0}" -f $objUser.Value
"Path={0}" -f $u.LocalPath
"SID={0}" -f $u.SID
}
catch {
"!!!!!Account Unknown!!!!!"
"Path={0}" -f $u.LocalPath
"SID={0}" -f $u.SID
Remove-CimInstance -inputobject $U -verbose
$Count++
}
}
$PC = [System.Net.DNS] :: GetHostByName($Null) HostName
Write-Host "on" $PC $Count "Account Unknown has been deleted"