I have the script where it captures blank profile paths in the profile list. I am not sure how to call the array and delete the whole key. It is saying path is not found as it is trying to run it from c:\windows\system32
how do i get it to go through the different paths it might have ? Right now I am just testing by blanking out one profile path
$Profiles = get-childitem “HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList”
$ProfileData = @()
foreach($Profile in $Profiles){
$ThisProfileInfo = $null
$ThisProfileInfo = @{Name=$Profile.Name;
ProfilePath=$Profile.GetValue("ProfileImagePath")}
if (!($ThisProfileInfo.ProfilePath)) {
$ProfileData += $ThisProfileInfo
}
}
$ProfileData
ForEach-Object{Remove-Item -Path ($Object.name)}
the error is ForEach-Object{Remove-Item -Path ($Object.name)}
Name Value
---- -----
Name HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\S-1-5-21-115761338-1150813220-1225219381-227283
ProfilePath
Remove-Item : Cannot find path 'C:\WINDOWS\system32\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows
NT\CurrentVersion\ProfileList\S-1-5-21-115761338-1150813220-1225219381-227283' because it does not exist.
At line:24 char:16
+ ForEach-Object{Remove-Item -Path ($Object.name)}
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (C:\WINDOWS\syst...25219381-227283:String) [Remove-Item], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.RemoveItemCommand