Problem removing user profile

I am trying to just remove a user profile from a remote machine.

I run a script against the machine using Invoke-command, but it leaves a profile of the user I ran the script as. I am trying to cleanup, by removing the profile afterwards using a different script.

I have tried using both of these:

Get-wmiobject -ComputerName servername -Class Win32_UserProfile | Where-Object { $_.sid -eq 'S-1-5-21-1334325200-504760778-2079600828-827513' } | Remove-wmiobject  -Confirm:$false

Get-CimInstance -ComputerName servername -Class Win32_UserProfile | Where-Object { $_.sid -eq 'S-1-5-21-1334325200-504760778-2079600828-827513' } | Remove-CimInstance  -Confirm:$false

I get this error:

At C:\Temp\ITScript\Services\RemoteServerKaceService\CheckKACEServiceOnRemoteUserInput.ps1:21 char:154
+ ... -504760778-2079600828-827513' } | Remove-CimInstance  -Confirm:$false
+                                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (Win32_UserProfi...8-207960082...):CimInstance) [Remove-CimInstance], CimException
    + FullyQualifiedErrorId : HRESULT 0x80070020,Microsoft.Management.Infrastructure.CimCmdlets.RemoveCimInstanceCommand

Any idea on how I can remove my profile remotely?


-Confirm is a [SwitchParameter] - not a [Boolean]. Either you provide it or you don’t … but you never provide a value for it. :wink:

Here a blog post about that topic:

Just was able to test, yes removing that -Confirm worked. Thanks!