A quick PowerShell 2 function for a Monday evening. A function to return properties from the WinNT provider, most commonly used to enumerate local group membership.
This should also work for domain groups (using the domain as the SystemName), although if the domain is Active Directory the LDAP provider returns far more information.
Once it’s there, you can see usage with:
Get-Help Get-LocalGroupMember
Get-Help Get-LocalGroupMember -Full
Get-Help Get-LocalGroupMember -Examples
And the function itself:
filter Get-LocalGroupMember {
<#
.SYNOPSIS
Gets members of a local group, by default the Administrators group.
.DESCRIPTION
Get-LocalGroupMember returns the members of a local group, including all properties exposed by the WinNT provider. Complex properties are returned in their raw form, additional work is needed to make sense of many.
.EXAMPLE
Get-LocalGroupMember Administrators
Return members of the administrator group on the local computer.
.EXAMPLE
Get-Content ServerList.txt | Get-LocalGroupMember Administrators
Return members of the administrator group all computers names in a text file.
.EXAMPLE
Get-ADComputer -Filter { operatingSystem -like "Windows 7*" } -Properties dnsHostName| Get-LocalGroupMember
Return members of the administrator group for all computers running Windows 7 in Active Directory
#>
[CmdletBinding()]
param (
# The group name to extract membership from. By default, the function uses Administrators.
[Parameter(Mandatory = $true)]
[Alias("Group", 'Identity')]
[String]$Name,
# The name of the system to execute against. By default, the function uses the local system.
[Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[Alias('DnsHostName')]
[String]$ComputerName = $env:ComputerName
)
([ADSI]('WinNT://{0}/{1}' -f $ComputerName, $Name)).Members() | ForEach-Object {
[ADSI]$_ | Add-Member ComputerName $ComputerName -PassThru -Force
}
}