r/PowerShell • • Jul 23 '19

Use PowerShell delete a user profile (step-by-step guide)

https://adamtheautomator.com/powershell-delete-user-profile/?utm_source=reddit&utm_medium=social&utm_campaign=newblogpostnotifications
120 Upvotes

59 comments sorted by

View all comments

2

u/Swarfega Jul 24 '19

Below, I'm finding the first user profile on the the local computer. You'll notice many useful tidbits of information like LastUseTime, SID and son.

1

u/adbertram Jul 24 '19

Will fix it. Thanks!

2

u/Swarfega Jul 24 '19

While you're here.

In this case, remove the user profile called UserA

The the example says FUSION?

Get-CimInstance -Class Win32_UserProfile | Where-Object { $_.LocalPath.split('')[-1] -eq 'FUSION' } | Remove-CimInstance

Also does this even work? Remove-CimInstance doesn't seem correct to me. I would have thought there would be a method to invoke the removal of the profile?

1

u/adbertram Jul 24 '19

In this case, remove the user profile called UserA

Got this updated. Thanks for the catch. Remove-CimInstance works. There used to be a Delete() method when invoking via Get-WmiObject.

2

u/Swarfega Jul 24 '19

Fails for me.

Remove-CimInstance : The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that take pipeline input.

1

u/adbertram Jul 24 '19

Hmm...are you running Windows 10? If so, what build? I'm on Win10 build 17134.

1

u/adbertram Jul 24 '19

It sounds like I need to mention some prereqs.

2

u/Swarfega Jul 24 '19

2012 R2. 5.1 of PS.