2
我有一個簡單的PowerShell代碼,如果服務器ping通,然後禁用本地管理員帳戶。如何將結果輸出到日誌文件,以便記錄我禁用的內容。PowerShell輸出結果從腳本到日誌文件
這是我迄今爲止
$computers = Get-ADComputer -filter {OperatingSystem -like "Windows Server*"} |
ForEach ($computer in $computers) {
$rtn = Test-Connection -CN $computer -Count 1 -BufferSize 16 -Quiet
IF($rtn -match 'True') {
write-host -ForegroundColor green $computer | Disable-localUserAccount -ComputerName $computer -username Administrator
} ELSE {
Write-host -ForegroundColor red $computer
}
}
你有什麼試圖寫入到文件中試過嗎?這樣做對於PowerShell來說非常容易,並且有多種方式可以實現。 – alroc
我試過這個,但不知道這是做到這一點的正確方法$ outputstring = $ computer $ outputstring -join「,」>> C:\ Create_Adminuser_computers.csv – user2785434