0
我想通过Powershell在WSUS API中运行一个查询,输出计算机名称,需要的补丁等,然后我需要将其注入到一个“日志”文件中,然后将它读入Splunk中我们可以使仪表盘等Powershell将表转换为数组
我当前的代码是
$computerscope = New-Object Microsoft.UpdateServices.Administration.ComputerTargetScope
$LogTime = Get-Date -Format "MM-dd-yyyy_hh-mm-ss"
$updatescope = New-Object Microsoft.UpdateServices.Administration.UpdateScope
$wsus.GetSummariesPerComputerTarget($updatescope,$computerscope) |
Select-Object $logtime,@{L=’ComputerTarget';E={($wsus.GetComputerTarget([guid]$_.ComputerTargetId)).FullDomainName}},
@{L=’NeededCount';E={($_.DownloadedCount + $_.NotInstalledCount)}},DownloadedCount,NotApplicableCount,NotInstalledCount,InstalledCount,FailedCount | Select-String Computer
输出出来是这样的:
@{05-13-2016_05-12-25=; ComputerTarget=########; NeededCount=12; DownloadedCount=0; NotApplicableCount=82245; NotInstalledCount=12; InstalledCount=23; FailedCount=0}
我需要它看起来像这样:
05-13-2016_05-12-25=; ComputerTarget=#######; NeededCount=12; DownloadedCount=0; NotApplicableCount=82245; NotInstalledCount=12; InstalledCount=23; FailedCount=0
如果你想尝试的问题的根源,我想表转换成阵,因此Splunk的可一行行读它,但这给出了我想要转换表:
$computerscope = New-Object Microsoft.UpdateServices.Administration.ComputerTargetScope
$LogTime = Get-Date -Format "MM-dd-yyyy_hh-mm-ss"
$updatescope = New-Object Microsoft.UpdateServices.Administration.UpdateScope
$wsus.GetSummariesPerComputerTarget($updatescope,$computerscope) |
Select-Object $logtime,@{L=’ComputerTarget';E={($wsus.GetComputerTarget([guid]$_.ComputerTargetId)).FullDomainName}},
@{L=’NeededCount';E={($_.DownloadedCount + $_.NotInstalledCount)}},DownloadedCount,NotApplicableCount,NotInstalledCount,InstalledCount,FailedCount `
这使输出:
05-13-2016_05-16-04 :
ComputerTarget : ########
NeededCount : 12
DownloadedCount : 0
NotApplicableCount : 82245
NotInstalledCount : 12
InstalledCount : 23
FailedCount : 0
因此,您所需要做的只是删除第一个示例的'@ {'和'}'? –