管道powershell脚本输出到文件

vecaoik1  于 2023-06-06  发布在  Shell
关注(0)|答案(1)|浏览(361)

抓我的头如何使这个脚本发送脚本的输出到一个文本文件,确定哪些组被删除,什么没有,下面是我的脚本任何人都能够协助我做错了什么?

$adgroups = Import-Csv "c:\test\groups.csv"
 $logfile = 'C:\test\process.txt'
 $Stream = [System.IO.StreamWriter]::new($logfile)

 # Iterate through your List
 foreach ($group in $adgroups) {
    try { # try/catch for some sort of error handling
        Remove-ADGroup -Identity $group.Name ##.Name if your CSV column is named "Name"
        Write-Host "$group was successfully removed"
        $Stream.WriteLine($group + ' was successfully removed')
    } catch {
        Write-Host "$group wasnt removed"
        $Stream.WriteLine($group + ' wasnt removed')
    }
}
$Stream.Close()

我尝试了各种使用$Stream将输出复制到文件的方法

相关问题