我有一个简单的Powershell代码,如果它们启动了ping服务器,然后禁用本地管理员帐户.如何将结果输出到日志文件,以便记录我已禁用的内容.
这就是我到目前为止所拥有的
$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
}
}
Run Code Online (Sandbox Code Playgroud)