Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SHELL

powerhsell write to output file from multiple jobs

$sb =  {
   Param($computer, $fileName, $outLog)
   net use "$computerc$" $password /user:$userName | Out-Null
   if(test-path $computerc$sc$fileName){
      [xml]$periods = Get-Content $computerc$sc$fileName
      $endDate = $periods.IndataDbf.ingredient.PeriodDetail.PeriodEndDate | select -last 1
         $output = "$computer;$endDate"
      }
   Else {
      $output = "$computer;$fileName Not Found"
   }
   Write-Output -InputObject $output
   net use "$computerc$" /de | Out-Null
}

foreach($computer in $computerName){
   while ((Get-Job -State Running).Count -ge 20) {
      Start-Sleep -Seconds 5;
   }
   Start-Job -Scriptblock $sb -ArgumentList $computer,$fileName,$outLog
}
Get-Job | Wait-Job | Receive-Job | Out-File -Append -FilePath $outLog
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #powerhsell #write #output #file #multiple #jobs
ADD COMMENT
Topic
Name
2+1 =