小编uSl*_*ckr的帖子

powershell输出结果从脚本到日志文件

我有一个简单的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)

powershell powershell-2.0 powershell-3.0

2
推荐指数
1
解决办法
7万
查看次数