抓我的头如何使这个脚本发送脚本的输出到一个文本文件,确定哪些组被删除,什么没有,下面是我的脚本任何人都能够协助我做错了什么?
$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将输出复制到文件的方法
1条答案
按热度按时间pcww981p1#
Out-File对你有用吗?
例如,在一个实施例中,
https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/out-file?view=powershell-7.3