Solved

Purging local accounts with powershell

Posted on 2015-01-06
4
84 Views
Last Modified: 2015-01-06
I came across this http://richardspowershellblog.wordpress.com/2012/06/08/working-with-profiles-2-deleting-profiles/ and I like the approach it removes all accounts except the administrator account but when I try I get Get-CimInstance error. How can I correct this and how exactly do I run it against multiple systems?

A modified version I tried but get the same error

Get-CimInstance -ClassName win32_group -Filter "name = 'administrators'" | 
Get-CimAssociatedInstance -Association win32_groupuser |
Where-Object { $_.SID -notlike "*-500" } | 
ForEach-Object {
    ([ADSI]"WinNT://.").delete("user",$_.Name)
}

Open in new window

0
Comment
Question by:stlhost
  • 2
4 Comments
 
LVL 68

Accepted Solution

by:
Qlemo earned 500 total points
ID: 40534009
Get-CimInstance requires PowerShell 3 or later.
0
 
LVL 39

Expert Comment

by:footech
ID: 40534140
It also communicates using the WS-Man protocol by default.  So unless you have PS Remoting setup on systems it won't work.  To get around this you can configure CIM sessions with the option to use DCOM, or just use the WMI cmdlets like Get-WmiObject.

Since you don't mention what the error is I can only guess.

It's unclear what exactly you're trying to do and whether you have a specific question.  Your title mentions local accounts, but the blog post is specifically not for local accounts and is in fact meant for deleting only a specified profile.
0
 
LVL 2

Author Comment

by:stlhost
ID: 40534151
Qlemo was correct I needed powershell 3. What I am wanting to do is purge local accounts except the admin account on remote workstations. There are random accounts and to many workstations to go through manually to check.
0
 
LVL 2

Author Closing Comment

by:stlhost
ID: 40534254
I did need powershell 3. The rest I figured out thanks
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Utilizing an array to gracefully append to a list of EmailAddresses
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now