您的位置:首页 > 理论基础

获取域内所有计算机本地管理员组内成员的POWESHELL CMDLET

2013-03-06 11:43 309 查看
代码:

网上找的脚本,忘了出处了。

默认是WRITE-HOST.

在DOS窗口下用powershell X.pwd > C:\x.TXT重定向符号可以输出到文件。

出处也忘记了。

$strFilter = "computer"
$objDomain = New-Object System.DirectoryServices.DirectoryEntry
$objSearcher = New-Object System.DirectoryServices.DirectorySearcher
$objSearcher.SearchRoot = $objDomain
$objSearcher.SearchScope = "Subtree"
$objSearcher.PageSize = 1000

$objSearcher.Filter = "(objectCategory=$strFilter)"

$colResults = $objSearcher.FindAll()

foreach ($i in $colResults)
{

$objComputer = $i.GetDirectoryEntry()
$strComputer = $objComputer.name

# If machine is up (True if any pings succeed and False if all failed) then carry on

if (test-connection -computername $strComputer -quiet)
{

$computer = [ADSI]("WinNT://" + $strComputer + ",computer")
#$computer.name
$Group = $computer.psbase.children.find("administrators")
#$Group.name

# This will list what’s currently in Administrator Group so you can verify the result

function ListAdministrators
{
$members= $Group.psbase.invoke("Members") | %{$_.GetType().InvokeMember("AdsPath", 'GetProperty', $null, $_, $null)}
$memclas= $Group.psbase.invoke("Members") | %{$_.GetType().InvokeMember("Class", 'GetProperty', $null, $_, $null)}
for($counter = 0; $counter -lt $members.count; $counter++) { [array]$result += "$($members[$counter]),$($memclas[$counter])" ; }
$result
}

Write-Host Server Name:
write-Host "`r`n"
$objComputer.dnsHostname
#Write-Host Administrators:
foreach($item in (ListAdministrators))
{
$ads  = (($item.Split(","))[0])
$type = (($item.Split(","))[1])
#Write-Host "AdsPath    : $($item)"
Write-Host "`r`n Name (Type): $(($ads.Split("/"))[-1]) ($($type))"
#Write-Host "Computer (Domain): $(($ads.Split("/"))[-2]) ($(($ads.Split("/"))[-3]))"
}
write-Host "`r`n"
Write-Host "++++++++++++++++++++++++"
}
}


效果图:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: