$VerbosePreference='continue' $Server= 'tot-ctx-prd02' $Profiles = Get-ChildItem -Directory \\$Server\c$\users | Select-Object -ExpandProperty name $OU='OU=User Accounts,OU=roser-total,DC=roser-total,DC=local' $ADusers= Get-ADuser -filter * -SearchBase $OU | Where-Object { $Profiles -ccontains $psitem.samaccountname } Get-ADComputer -filter "name -like '$Server'" | ForEach-Object { Write-Verbose $psitem.DNSHostname Invoke-Command -ComputerName $psitem.DNSHostname -ScriptBlock { $VerbosePreference='continue'; foreach($sid in $args) { Write-Verbose $SID Get-WMIObject -class Win32_UserProfile -Filter "SID='$sid'" | Remove-WmiObject -Verbose } } -ArgumentList ($ADusers).SID }