I'm trying to write a powershell script to delete a Windows Server 2008 R2 profile and because of the whole registry key thing I'm trying to do it using Remove-WmiObject, but I keep getting an error when I pipe the object to Remove-WmiObject. I'm not really sure what it is I'm doing wrong. I'm using remoting to do this.
Invoke-Command remotemachine {Get-WmiObject Win32_UserProfile | Where-Object {$_.LocalPath -eq"C:\Users\user"} | Remove-WmiObject}
Everytime I run the command I get a + CategoryInfo : NotSpecified: (:) [Remove-WmiObject], ArgumentException error. I've tried looking up how to pipe commands to Remove-WmiObject and they all show exactly what I'm doing, even the examples on msdn show simply piping it to Remove-WmiObject. I'm fairly new to powershell so I'm not really sure what I'm doing wrong here. Any and all help is very appreciated. Thanks.
I have looked at a similar post at http://social.technet.microsoft.com/Forums/en-US/ITCG/thread/3cdef173-b6a8-4627-b681-a0238be617c4/ but the answer to that is simply an external program. I want to be able to do this with powershell exclusively