Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Purging local accounts with powershell

Posted on 2015-01-06
4
Medium Priority
?
110 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 71

Accepted Solution

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

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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A procedure for exporting installed hotfix details of remote computers using powershell
Previously, on our Nano Server Deployment series, we've created a new nano server image and deployed it on a physical server in part 2. Now we will go through configuration.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

604 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