要怎麼把文字存成檔案再執行?
$Result = @()
foreach($server in (gc .\servers.txt)){
$computer = [ADSI](”WinNT://” + $server + “,computer”)
$Group = $computer.psbase.children.find(”Administrators”)
function getAdmins
{$members = ($Group.psbase.invoke(”Members”) | %{$_.GetType().InvokeMember(”Adspath”, ‘GetProperty’, $null, $_, $null)}) -replace ('WinNT://DOMAIN/' + $server + '/'), '' -replace ('WinNT://DOMAIN/', 'DOMAIN\') -replace ('WinNT://', '')
$members}
$Result += Write-Output "SERVER: $server"
$Result += Write-Output ' '
$Result += ( getAdmins )
$Result += Write-Output '____________________________'
$Result += Write-Output ' '
}
$Result > d:\results.txt
Invoke-Item d:\results.txt
存檔副檔名 .ps1 (ps one) ,先啟動 powershell ,再去執行即可
參考文件:
http://technet.microsoft.com/en-us/library/ee176949.aspx
沒有留言:
張貼留言