【发布时间】:2019-10-10 20:11:07
【问题描述】:
我有一个使用 poshwsus 模块的 PowerShell 脚本,如下所示:
$FileOutput = "C:\WSUSReport\WSUSReport.csv"
$ProcessLog = "C:\WSUSReport\QueryLog2.txt"
$WSUSServers = "C:\WSUSReport\Computers.txt"
$WSUSPort = "8530"
import-module poshwsus
ForEach ($Server in Get-Content $WSUSServers)
{
& connect-poshwsusserver $Server -port $WSUSPort | out-file $ProcessLog -append
$r1 = & Get-PoshWSUSClient | select @{name="Computer";expression={$_.FullDomainName}},@{name="LastUpdated";expression={if ([datetime]$_.LastReportedStatusTime -gt [datetime]"1/1/0001 12:00:00 AM") {$_.LastReportedStatusTime} else {$_.LastSyncTime}}}
$r2 = & Get-PoshWSUSUpdateSummaryPerClient -UpdateScope (new-poshwsusupdatescope) -ComputerScope (new-poshwsuscomputerscope) | Select Computer,NeededCount,DownloadedCount,NotApplicableCount,NotInstalledCount,InstalledCount,FailedCount
}
我需要做的是导出 CSV 输出,包括带有列的结果(如“内部连接”):
Computer, NeededCount, DownloadedCount, NotApplicableCount, NotINstalledCount, InstalledCount, FailedCount, LastUpdated
我尝试在 foreach 中使用下面的行,但它没有按我预期的那样工作。
$r1 + $r2 | export-csv -NoTypeInformation -append $FileOutput
如果您能提供帮助或建议,我将不胜感激。
EDIT --> 我得到的输出:
ComputerName LastUpdate
X A
Y B
X
Y
所以没有错误,前两行来自 $r2,最后两行来自 $r1,它没有像我预期的那样加入表格。
谢谢!
【问题讨论】:
-
您是否收到错误消息或意外输出?您是否能够共享该输出(如果需要,删除敏感信息)?
-
意外输出。让我编辑问题。
-
如果您不想重新发明轮子并遇到与在 PowerShell 中加入对象相关的每个陷阱(例如:Not all properties displayed)和(性能)问题,您可能需要查看此@987654322 @cmdlet。我猜你的语法很简单:
$r1 | Join $r2 -On Computer
标签: powershell powershell-5.0 poshwsus