Multi-Threading in PowerShell: Difference between revisions

From WikiWiki
Jump to navigation Jump to search
(Created page with "<syntaxhighlight lang="powershell"> Get-Job Receive-Job Remove-Job Resume-Job Start-Job Stop-Job Suspend-Job Wait-Job </syntaxhighlight> create a new the function create the ...")   (change visibility)
 
No edit summary   (change visibility)
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
<syntaxhighlight lang="powershell">
<syntaxhighlight language="powershell">
Get-Job
Get-Job
Receive-Job
Receive-Job
Line 10: Line 10:
</syntaxhighlight>
</syntaxhighlight>


create a new the function
create the job (pass arguments) and keep the ID as reference
get job status
receive the data


<syntaxhighlight lang="powershell">
 
*create a new the function
*create the job (pass arguments) and keep the ID as reference
*get job status
*receive the data
 
<syntaxhighlight language="powershell">
$templist=$null
$templist=$null
$scriptblock={
$scriptblock={

Latest revision as of 22:50, 21 August 2020

Get-Job
Receive-Job
Remove-Job
Resume-Job
Start-Job
Stop-Job
Suspend-Job
Wait-Job


  • create a new the function
  • create the job (pass arguments) and keep the ID as reference
  • get job status
  • receive the data
$templist=$null
$scriptblock={
  param($subscriptionName,$proxycreds)
  [System.Net.WebRequest]::DefaultWebProxy.Credentials = $proxycreds 
  #select-azuresubscription -SubscriptionName $subscriptionName
  (Get-AzureService).servicename | foreach {Get-AzureVM -ServiceName $_ }
}
$id = Start-Job –Name getAllVMOptions –Scriptblock $scriptblock -ArgumentList @($subscriptionName, $global:proxycreds) | select id
while((Get-Job -id $id.id).State -ne "completed" )
{
  $time++
  if($time -ge 100)
    {$time=0}
  #write-host "running"
  Write-Progress -activity "Waiting..." -status "Time: $time"  -PercentComplete ($time)
  Start-Sleep 1 
}
$templist = Receive-Job -Id $id.id