-1

私はこの驚くべき答えを使用しており、RunSpacePools を使用して CSV ファイルを出力しましたが、私の CSV ファイルには空白行があり、空白行がどこから来ているのかわかりません。

空白行はメモ帳に次のように表示されます,,,

    IF(Get-Command Get-SCOMAlert -ErrorAction SilentlyContinue){}ELSE{Import-Module OperationsManager}

    "Get Pend reboot servers from prod"
New-SCOMManagementGroupConnection -ComputerName ProdServer1

$AlertData = get-SCOMAlert -Criteria "Severity = 1 AND ResolutionState < 254 AND Name = 'Pending Reboot'" | Select NetbiosComputerName

    "Get Pend reboot servers from test"
#For test information
New-SCOMManagementGroupConnection -ComputerName TestServer1

$AlertData += Get-SCOMAlert -Criteria "Severity = 1 AND ResolutionState < 254 AND Name = 'Pending Reboot'" | Select NetbiosComputerName

    "Remove duplicates"
$AlertDataNoDupe = $AlertData | Sort NetbiosComputerName -Unique

$scriptblock = {
 Param([string]$server)

$csv = Import-Csv D:\Scripts\MaintenanceWindow2.csv
$window = $csv | where {$_.Computername -eq "$server"} | % CollectionName
$SCCMWindow = IF ($window){$window}ELSE{"NoDeadline"}

 $PingCheck = Test-Connection -Count 1 $server -Quiet -ErrorAction SilentlyContinue
        IF($PingCheck){$PingResults = "Alive"}
        ELSE{$PingResults = "Dead"}

 Try{$operatingSystem = Get-WmiObject Win32_OperatingSystem -ComputerName $server -ErrorAction Stop
        $LastReboot = [Management.ManagementDateTimeConverter]::ToDateTime($operatingSystem.LastBootUpTime)
        $LastReboot.DateTime}
        Catch{$LastReboot = "Access Denied!"}

 #create custom object as output for CSV.
 [PSCustomObject]@{    
 Server=$server
 MaintenanceWindow=$SCCMWindow
 Ping=$PingResults
 LastReboot=$LastReboot
 }#end custom object
}#script block end

$RunspacePool = [RunspaceFactory]::CreateRunspacePool(100,100)
$RunspacePool.Open()
$Jobs = 
 foreach ( $item in $AlertDataNoDupe )
{
 $Job = [powershell]::Create().
        AddScript($ScriptBlock).
        AddArgument($item.NetbiosComputerName)
 $Job.RunspacePool = $RunspacePool

 [PSCustomObject]@{
  Pipe = $Job
  Result = $Job.BeginInvoke()
 }
}

Write-Host 'Working..' -NoNewline

 Do {
  Write-Host '.' -NoNewline
  Start-Sleep -Milliseconds 500
} While ( $Jobs.Result.IsCompleted -contains $false)

Write-Host ' Done! Writing output file.'
Write-host "Output file is d:\scripts\runspacetest4.csv"

$(ForEach ($Job in $Jobs)
{ $Job.Pipe.EndInvoke($Job.Result) }) |
 Export-Csv d:\scripts\runspacetest4.csv -NoTypeInformation

$RunspacePool.Close()
$RunspacePool.Dispose()
4

1 に答える 1