获取本地计算机的用户组和组成员
function Get-LocalGroups() { net localgroup | ?{ $_ -match "^\*.*" } | %{ $_.SubString(1) }; } function Get-LocalGroupMembers() { param ([string]$groupName = $(throw "Need a name") ) $lines = net localgroup $groupName $found = $false for ($i = 0; $i -lt ($lines.Length-1); $i++ ) { if ( $found ) { if ( -not $lines[$i].StartsWith("命令成功完成")) { $output = $lines[$i] + "," + $groupName Write-Output $output } } elseif ( $lines[$i] -match "^----" ) { $found = $true; } } } function fn(){ $lines = Get-LocalGroups; $found =$false; for ($i = 0; $i -lt $lines.Length; $i++ ) { if ( -not $lines[$i].StartsWith("命令成功完成")) { Get-LocalGroupMembers $lines[$i] } } } fn