Powershell 獲取本地組成員信息

工做當中須要查看本地組成員信息,從網上看到使用net localgroup 命令能夠實現本地組成員信息,通過再加工獲得以下信息,備忘至此!ide

$localgroups = "Administrators","Remote Desktop Users"
$result = @()
foreach($group in $localgroups){
$groupmembers = net localgroup $group
foreach($member in $groupmembers){
if($member -like "CONTOSO*" -and $member -ne "CONTOSO\Domain Admins"){
$psobject = New-Object psobject
$psobject | Add-Member -MemberType NoteProperty -Name GroupName -Value $group
$psobject | Add-Member -MemberType NoteProperty -Name Members -Value $member
$result+=$psobject
}
}
}
$resultit

相關文章
相關標籤/搜索