Reputation: 61
I want to fetch the list of users that are present in local Administrators
group by using Get-WMIObject
.
I fetched the group name using below command :
get-wmiobject win32_group -Filter "Name='Administrators'"
Upvotes: 0
Views: 16075
Reputation: 13227
I have a function that I use for this task:
function Get-LocalAdministrators {
param ($strcomputer)
$admins = Get-WmiObject win32_groupuser –computer $strcomputer
$admins = $admins |? {$_.groupcomponent –like '*"Administrators"'}
$admins | ForEach-Object {
$_.partcomponent –match ".+Domain\=(.+)\,Name\=(.+)$" > $nul
$matches[1].trim('"') + "\" + $matches[2].trim('"')
}
}
Usage:
Get-LocalAdministrators computer01
And to run against the local computer:
Get-LocalAdministrators localhost
Upvotes: 4