Get local administrators

by monsterlab at 2013-04-07 07:34:49

This one has me stumped. It seems pretty simple, but I can only get it to work when I do each computer one at a time.

Basically, I just want to scan a top-level OU and all child OUS and get the members of the local administrator group on each server in that OU. I’d like the output to be in a CSV that lists the server name and the members of the group. I’ve been using the following in PowerShell 3.0:

Get-CimInstance -ClassName win32_group -Filter “name = ‘administrators’” |Get-CimAssociatedInstance -Association win32_groupuser

It works when I do one server at a time, but I can’t get it to properly loop through a txt file with server names from the OU. Is there a better way to do this?

Thanks for your help!
by DonJ at 2013-04-07 08:14:42
So, be aware that Get-CimInstance relies on WinRM (Remoting). Do you have WinRM enabled on all of your servers?
by monsterlab at 2013-04-07 13:13:34
Thanks for the reply. That’s good to know! I do not have WinRM enabled on everything. Does this mean I’d need do the equivalent with Get-WMI?
by DonJ at 2013-04-07 21:49:27
You could. You can use CIM but would need to manually establish a DCOM CIMSession first.