Powershell array delete Name path

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)}

mmoore5553,
Welcome to the forum. :wave:t4:

I’m not exactly sure what your actual issue is but your code could be simplified to this I think:

$ProfileList = Get-ChildItem -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList'

$ProfileData = 
foreach ($Profile in $ProfileList) {
    [PSCustomObject]@{
        Name             = $Profile.Name
        ProfileImagePath = $Profile.GetValue('ProfileImagePath')
    }
}
$ProfileData