Hello I'm trying to delete old user profiles with powershell. I have been able to successfully delete profiles when they are found in the registry with the following script.
$localProfilePath = "C:\\Users\\$User"
$WMIQuery = "SELECT * FROM Win32_UserProfile WHERE localpath = '$localProfilePath'"
$profile = Get-WmiObject -Query $WMIQuery -ComputerName $Computer_Name
Remove-WmiObject -InputObject $profile
When I try to delete profiles that are not found in the registry I get the following error.
Remove-WmiObject : Cannot bind argument to parameter 'InputObject' because it is null.
I have found that several older profiles are not found in the registry for some reason. It may be because of a update. I tried using other methods but keep getting errors when I try to delete the profile. I think that windows is blocking the hidden files from being deleted in a profile. Does anyone know how to fix this issue or know a better way of doing it?