I am trying to write data to external array while running a powershell job-
This is my code sample that I' m trying-
$datafromJob = @()
$wmijobs = @()
foreach ($c in $computers) {
$wmijobs += Start-Job -Name WMIInventory -ScriptBlock {
$jobdata = get-wmiobject -ComputerName $args[0] -Class win32_computersystem -Credential $Cred -ErrorVariable Err -ErrorAction SilentlyContinue
if ($Err.length) {
Add-content -Path D:\InventoryError.log -Force -Value $Err
$details = @{
Domain = "Error"
Manufacturer = "Error"
Computer = $args[0]
Name = "Error"
}
$args[3] += New-Object PSObject -Property $details
}
if ($jobdata.length) {
$details = @{
Domain = $jobdata.Domain
Manufacturer = $jobdata.Manufacturer
Computer = $args[2]
Name = $jobdata.Name
}
$args[3] += New-Object PSObject -Property $details
}
-ArgumentList $c, $Cred, "Test", $datafromJob
}
}
Expecting Output in $datafromJob Variable, but the end of job and loop variable is empty, M not getting how it will work, anyhelp,
Do let me know if any queries on this question