0
작업을 시작하는 데 어려움이 있으며 문제가 무엇인지 알아내는 데 어려움이 있습니다. 대부분의 작업이 전부가 아니라면 대부분 완료되지 않습니다. 아래 코드는 작업으로 시작하지 않을 때 올바르게 작동했습니다.Powershell Start-Job 작업이 완료되지 않았습니다.
$timer = [System.Diagnostics.Stopwatch]::StartNew()
$allServers = Import-Csv "C:\temp\input.csv"
$password = GC "D:\Stored Credentials\PW" | ConvertTo-SecureString
$allServers | % {
Start-Job -ArgumentList $_.ComputerName,$_.Domain -ScriptBlock {
param($sv,$dm)
$out = @()
#Determine credential to use and create password
$password = GC "D:\Stored Credentials\PW" | ConvertTo-SecureString
switch ($dm) {
USA {$user = GC "D:\Stored Credentials\MIG"}
DEVSUB {$user = GC "D:\Stored Credentials\DEVSUB"}
default {$cred = ""}
}
$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $user,$password
#Query total cpus
$cpu = ((GWMI win32_processor -ComputerName $sv -Credential $cred).NumberOfLogicalProcessors | Measure-Object).Count
$outData = New-Object PSObject
$outData | Add-Member -Type NoteProperty -Name "ComputerName" -Value $sv
$outData | Add-Member -Type NoteProperty -Name "#CPU" -Value $cpu
$out += $outData
return $out
}
}
while (((Get-Job).State -contains "Running") -and $timer.Elapsed.TotalSeconds -lt 60) {
Start-Sleep -Seconds 10
Write-Host "Waiting for all jobs to complete"
}
Get-Job | Receive-Job | Select-Object -Property * -ExcludeProperty RunspaceId | Out-GridView