?
Solved

Purging local accounts with powershell

Posted on 2015-01-06
4
Medium Priority
?
103 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 70

Accepted Solution

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

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

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
The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
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ā€¦
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

764 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