MyITGuy
3/24/2014 - 8:40 PM

Corrects an issue whereas a user is constantly logged in with a TEMP profile when a profile directory is no longer on the file system. This

Corrects an issue whereas a user is constantly logged in with a TEMP profile when a profile directory is no longer on the file system. This is due to the profile still existing in the registry.

Get-ItemProperty -Path "Registry::HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\$((New-Object System.Security.Principal.NTAccount($env:USERNAME)).Translate([System.Security.Principal.SecurityIdentifier]).Value).bak" -Name "ProfileImagePath" | Select -ExpandProperty ProfileImagePath | % {$ProfileImagePath = "$($_)" ; Write-Host "ProfileImagePath: $($ProfileImagePath) - " -NoNewline ; if ((Test-Path $ProfileImagePath) -eq $true) {Write-Host "Profile image path found." -ForegroundColor Green} else {Write-Host "Profile image path does not exist." -ForegroundColor Red ; Remove-Item -Path "Registry::HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\$((New-Object System.Security.Principal.NTAccount($env:USERNAME)).Translate([System.Security.Principal.SecurityIdentifier]).Value).bak" -Confirm}}