需要powershell帮助导出4个数据部分

时间:2016-02-16 17:57:25

标签: csv powershell

以下列表在我的工作中比较了我们AD的名称列表。但是,每个部分都列出了很多名称,导致我无法向上滚动。我尝试过使用。\ ylaudit2.ps1 | out-file workdayaudit1.csv它只给了我一个空白的csv文件。有人可以帮我吗?

Category

1 个答案:

答案 0 :(得分:0)

您无法保存输出的原因是因为您正在使用Write-HostWrite-Host仅将文本写入交互式控制台,例如。状态信息等。

如果您需要能够将输出保存到文件,则需要在输出要保存的数据的行上删除Write-Host(或使用Write-Output),因此对象将是传递给管道,因此| Out-File可以捕获并保存它们。

实施例。替换:

Write-Host "`nDatabase authenticated Yodle Live users associated with AD accounts:" -ForegroundColor Yellow
Write-Host $DBUsersInAD | FL

#lots of code....
#...

Write-Host "`nEnabled Yodle Live accounts associated with disabled AD Users:" -ForegroundColor Yellow
Write-Host $inADandDisabled | FL
Write-Host "`nEnabled Yodle Live accounts not associated with any AD User:" -ForegroundColor Yellow
Write-Host $notinAD | FL

使用:

"Database authenticated Yodle Live users associated with AD accounts:"
$DBUsersInAD

#lots of code....
#...

"Enabled Yodle Live accounts associated with disabled AD Users:"
$inADandDisabled
"Enabled Yodle Live accounts not associated with any AD User:"
$notinAD