# Problem removing user profile

**URL:** <https://forums.powershell.org/t/problem-removing-user-profile/21036>\
**Category:** PowerShell Help\
**Created:** [November 28, 2022, 9:48pm UTC](https://forums.powershell.org/t/problem-removing-user-profile/21036 "2022-11-28T21:48:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![matt1974](https://avatars.discourse-cdn.com/v4/letter/m/dbc845/32.png) [@matt1974](https://forums.powershell.org/u/matt1974)\
**Post date:** [November 28, 2022, 9:48pm UTC](https://forums.powershell.org/t/problem-removing-user-profile/21036/1 "2022-11-28T21:48:49Z")

</div>

Hello,  
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:

```auto
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:

```auto
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?

Thanks!

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [November 28, 2022, 10:25pm UTC](https://forums.powershell.org/t/problem-removing-user-profile/21036/2 "2022-11-28T22:25:44Z")

</div>

> [@matt1974](#):
>
> ```auto
> + ... -504760778-2079600828-827513' } | Remove-CimInstance -Confirm:$false
> + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> ```

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

Here a blog post about that topic:

> **[Delete User Profiles with PowerShell & CIM](https://adamtheautomator.com/powershell-delete-user-profile/)**
>
> Use PowerShell and the CIM command to delete user profiles on Windows systems in this step-by-step guide.

---

<div class="post-metadata">

**Author:** ![matt1974](https://avatars.discourse-cdn.com/v4/letter/m/dbc845/32.png) [@matt1974](https://forums.powershell.org/u/matt1974)\
**Post date:** [November 30, 2022, 12:37am UTC](https://forums.powershell.org/t/problem-removing-user-profile/21036/3 "2022-11-30T00:37:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:16pm UTC](https://forums.powershell.org/t/problem-removing-user-profile/21036/4 "2024-05-16T20:16:17Z")

</div>

Closed on May 16, 2024, 8:16pm UTC


