# encoding: ascii
# api: powershell
# title: Get-LocalGroupMembers
# description: Enumerate users of a given local group. Uses WMI. Outputs strings, sorry about that.
# version: 0.1
# type: function
# author: Carter Shanklin
# license: CC0
# function: Get-LocalGroupMembers
# x-poshcode-id: 3678
# x-archived: 2012-10-21T16:42:56
# x-published: 2012-10-04T07:08:00
#
#
function Get-LocalGroupMembers {
	param($groupname)

	$pattern = "*Name=`"$groupname`""
	$groupusers = gwmi Win32_GroupUser | Where { $_.GroupComponent -like $pattern }

	# Now extract the usernames.
	foreach ($user in $groupusers) {
		if ($user.PartComponent -match 'Name="([^"]+)') {
			Write-Output $matches[1]
		}
	}
}

# Use it like this.
# Get-GroupMembers Administrators
