diff --git a/reference/5.1/Microsoft.PowerShell.Core/Start-Job.md b/reference/5.1/Microsoft.PowerShell.Core/Start-Job.md index 39cdc31d0479..ff59780f1f53 100644 --- a/reference/5.1/Microsoft.PowerShell.Core/Start-Job.md +++ b/reference/5.1/Microsoft.PowerShell.Core/Start-Job.md @@ -2,7 +2,7 @@ external help file: System.Management.Automation.dll-Help.xml Locale: en-US Module Name: Microsoft.PowerShell.Core -ms.date: 12/12/2022 +ms.date: 09/29/2023 online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/start-job?view=powershell-5.1&WT.mc_id=ps-gethelp schema: 2.0.0 title: Start-Job @@ -180,7 +180,7 @@ This example starts a job that collects a large amount of map data and then save file. ```powershell -Start-Job -Name GetMappingFiles -InitializationScript {Import-Module MapFunctions} -ScriptBlock { +Start-Job -Name GetMappingFiles -InitializationScript {Import-Module -Name MapFunctions} -ScriptBlock { Get-Map -Name * | Set-Content -Path D:\Maps.tif } -RunAs32 ``` @@ -196,7 +196,7 @@ This example uses the `$input` automatic variable to process an input object. Us view the job's output. ```powershell -Start-Job -ScriptBlock { Get-Content $input } -InputObject "C:\Servers.txt" +Start-Job -ScriptBlock { Get-Content -Path $input } -InputObject "C:\Servers.txt" Receive-Job -Name Job45 -Keep ``` diff --git a/reference/5.1/Microsoft.PowerShell.Core/Stop-Job.md b/reference/5.1/Microsoft.PowerShell.Core/Stop-Job.md index 3046d72170e7..380f4e245e0e 100644 --- a/reference/5.1/Microsoft.PowerShell.Core/Stop-Job.md +++ b/reference/5.1/Microsoft.PowerShell.Core/Stop-Job.md @@ -2,7 +2,7 @@ external help file: System.Management.Automation.dll-Help.xml Locale: en-US Module Name: Microsoft.PowerShell.Core -ms.date: 12/12/2022 +ms.date: 09/29/2023 online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/stop-job?view=powershell-5.1&WT.mc_id=ps-gethelp schema: 2.0.0 title: Stop-Job @@ -76,7 +76,7 @@ feature. ```powershell $s = New-PSSession -ComputerName Server01 -Credential Domain01\Admin02 -$j = Invoke-Command -Session $s -ScriptBlock {Start-Job -ScriptBlock {Get-EventLog System}} +$j = Invoke-Command -Session $s -ScriptBlock {Start-Job -ScriptBlock {Get-EventLog -LogName System}} Invoke-Command -Session $s -ScriptBlock { Stop-job -Job $Using:j } ``` @@ -168,14 +168,14 @@ selected job. ### Example 7: Stop a job on a remote computer ```powershell -$j = Invoke-Command -ComputerName Server01 -ScriptBlock {Get-EventLog System} -AsJob +$j = Invoke-Command -ComputerName Server01 -ScriptBlock {Get-EventLog -LogName System} -AsJob $j | Stop-Job -PassThru ``` ```Output Id Name State HasMoreData Location Command -- ---- ---- ----------- -------- ------- -5 Job5 Stopped True user01-tablet get-eventlog system +5 Job5 Stopped True user01-tablet Get-EventLog -LogName Sy... ``` This example shows how to use the `Stop-Job` cmdlet to stop a job that is running on a remote diff --git a/reference/5.1/Microsoft.PowerShell.Core/Wait-Job.md b/reference/5.1/Microsoft.PowerShell.Core/Wait-Job.md index 15af2049ee17..0b008bb89457 100644 --- a/reference/5.1/Microsoft.PowerShell.Core/Wait-Job.md +++ b/reference/5.1/Microsoft.PowerShell.Core/Wait-Job.md @@ -2,7 +2,7 @@ external help file: System.Management.Automation.dll-Help.xml Locale: en-US Module Name: Microsoft.PowerShell.Core -ms.date: 12/12/2022 +ms.date: 09/29/2023 online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/wait-job?view=powershell-5.1&WT.mc_id=ps-gethelp schema: 2.0.0 title: Wait-Job @@ -123,8 +123,8 @@ to determine how many of the jobs are finished. ### Example 3: Determine when the first job finishes ```powershell -$s = New-PSSession (Get-Content Machines.txt) -$c = 'Get-EventLog -LogName System | where {$_.EntryType -eq "error" --and $_.Source -eq "LSASRV"} | Out-File Errors.txt' +$s = New-PSSession -ComputerName (Get-Content -Path .\Machines.txt) +$c = 'Get-EventLog -LogName System | Where-Object {$PSItem.EntryType -eq "error" --and $PSItem.Source -eq "LSASRV"} | Out-File -FilePath Errors.txt' Invoke-Command -Session $s -ScriptBlock {Start-Job -ScriptBlock {$Using:c} Invoke-Command -Session $s -ScriptBlock {Wait-Job -Any} ``` @@ -155,7 +155,7 @@ The fourth command uses `Invoke-Command` to run a `Wait-Job` command in the sess ### Example 4: Set a wait time for jobs on remote computers ```powershell -PS> $s = New-PSSession Server01, Server02, Server03 +PS> $s = New-PSSession -ComputerName Server01, Server02, Server03 PS> $jobs = Invoke-Command -Session $s -ScriptBlock {Start-Job -ScriptBlock {Get-Date}} PS> $done = Invoke-Command -Session $s -ScriptBlock {Wait-Job -Timeout 30} PS> @@ -211,7 +211,7 @@ This command uses the job name to identify the job for which to wait. ### Example 8: Wait for jobs on local computer started with Start-Job ```powershell -$j = Start-Job -ScriptBlock {Get-ChildItem *.ps1| where {$_.lastwritetime -gt ((Get-Date) - (New-TimeSpan -Days 7))}} +$j = Start-Job -ScriptBlock {Get-ChildItem -Filter *.ps1| Where-Object {$PSItem.LastWriteTime -gt ((Get-Date) - (New-TimeSpan -Days 7))}} $j | Wait-Job ``` @@ -231,7 +231,7 @@ finishes, the command displays the job object, which contains information about ### Example 9: Wait for jobs started on remote computers by using Invoke-Command ```powershell -$s = New-PSSession Server01, Server02, Server03 +$s = New-PSSession -ComputerName Server01, Server02, Server03 $j = Invoke-Command -Session $s -ScriptBlock {Get-Process} -AsJob $j | Wait-Job ``` diff --git a/reference/7.2/Microsoft.PowerShell.Core/Start-Job.md b/reference/7.2/Microsoft.PowerShell.Core/Start-Job.md index 4ec84b3402a8..e4d0ed84f25c 100644 --- a/reference/7.2/Microsoft.PowerShell.Core/Start-Job.md +++ b/reference/7.2/Microsoft.PowerShell.Core/Start-Job.md @@ -2,7 +2,7 @@ external help file: System.Management.Automation.dll-Help.xml Locale: en-US Module Name: Microsoft.PowerShell.Core -ms.date: 12/12/2022 +ms.date: 09/29/2023 online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/start-job?view=powershell-7.2&WT.mc_id=ps-gethelp schema: 2.0.0 title: Start-Job @@ -220,7 +220,7 @@ This example starts a job that collects a large amount of map data and then save file. ```powershell -Start-Job -Name GetMappingFiles -InitializationScript {Import-Module MapFunctions} -ScriptBlock { +Start-Job -Name GetMappingFiles -InitializationScript {Import-Module -Name MapFunctions} -ScriptBlock { Get-Map -Name * | Set-Content -Path D:\Maps.tif } ``` @@ -235,7 +235,7 @@ This example uses the `$input` automatic variable to process an input object. Us view the job's output. ```powershell -Start-Job -ScriptBlock { Get-Content $input } -InputObject "C:\Servers.txt" +Start-Job -ScriptBlock { Get-Content -Path $input } -InputObject "C:\Servers.txt" Receive-Job -Name Job45 -Keep ``` @@ -309,8 +309,8 @@ Major Minor Patch PreReleaseLabel BuildLabel ``` ```powershell -$job = Start-Job { $PSVersionTable.PSVersion } -PSVersion 5.1 -Receive-Job $job +$job = Start-Job -ScriptBlock { $PSVersionTable.PSVersion } -PSVersion 5.1 +Receive-Job -Job $job ``` ```Output diff --git a/reference/7.2/Microsoft.PowerShell.Core/Stop-Job.md b/reference/7.2/Microsoft.PowerShell.Core/Stop-Job.md index 674caab53da6..659e0c265ace 100644 --- a/reference/7.2/Microsoft.PowerShell.Core/Stop-Job.md +++ b/reference/7.2/Microsoft.PowerShell.Core/Stop-Job.md @@ -2,7 +2,7 @@ external help file: System.Management.Automation.dll-Help.xml Locale: en-US Module Name: Microsoft.PowerShell.Core -ms.date: 12/12/2022 +ms.date: 09/29/2023 online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/stop-job?view=powershell-7.2&WT.mc_id=ps-gethelp schema: 2.0.0 title: Stop-Job @@ -76,7 +76,7 @@ feature. ```powershell $s = New-PSSession -ComputerName Server01 -Credential Domain01\Admin02 -$j = Invoke-Command -Session $s -ScriptBlock {Start-Job -ScriptBlock {Get-EventLog System}} +$j = Invoke-Command -Session $s -ScriptBlock {Start-Job -ScriptBlock {Get-EventLog -LogName System}} Invoke-Command -Session $s -ScriptBlock { Stop-job -Job $Using:j } ``` @@ -168,14 +168,14 @@ selected job. ### Example 7: Stop a job on a remote computer ```powershell -$j = Invoke-Command -ComputerName Server01 -ScriptBlock {Get-EventLog System} -AsJob +$j = Invoke-Command -ComputerName Server01 -ScriptBlock {Get-EventLog -LogName System} -AsJob $j | Stop-Job -PassThru ``` ```Output Id Name State HasMoreData Location Command -- ---- ---- ----------- -------- ------- -5 Job5 Stopped True user01-tablet get-eventlog system +5 Job5 Stopped True user01-tablet Get-EventLog -LogName Sy... ``` This example shows how to use the `Stop-Job` cmdlet to stop a job that is running on a remote diff --git a/reference/7.2/Microsoft.PowerShell.Core/Wait-Job.md b/reference/7.2/Microsoft.PowerShell.Core/Wait-Job.md index 114e1525d757..59ae2815c425 100644 --- a/reference/7.2/Microsoft.PowerShell.Core/Wait-Job.md +++ b/reference/7.2/Microsoft.PowerShell.Core/Wait-Job.md @@ -2,7 +2,7 @@ external help file: System.Management.Automation.dll-Help.xml Locale: en-US Module Name: Microsoft.PowerShell.Core -ms.date: 12/12/2022 +ms.date: 09/29/2023 online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/wait-job?view=powershell-7.2&WT.mc_id=ps-gethelp schema: 2.0.0 title: Wait-Job @@ -123,8 +123,8 @@ to determine how many of the jobs are finished. ### Example 3: Determine when the first job finishes ```powershell -$s = New-PSSession (Get-Content Machines.txt) -$c = 'Get-EventLog -LogName System | where {$_.EntryType -eq "error" --and $_.Source -eq "LSASRV"} | Out-File Errors.txt' +$s = New-PSSession -ComputerName (Get-Content -Path .\Machines.txt) +$c = 'Get-EventLog -LogName System | Where-Object {$PSItem.EntryType -eq "error" --and $PSItem.Source -eq "LSASRV"} | Out-File -FilePath Errors.txt' Invoke-Command -Session $s -ScriptBlock {Start-Job -ScriptBlock {$Using:c} Invoke-Command -Session $s -ScriptBlock {Wait-Job -Any} ``` @@ -155,7 +155,7 @@ The fourth command uses `Invoke-Command` to run a `Wait-Job` command in the sess ### Example 4: Set a wait time for jobs on remote computers ```powershell -PS> $s = New-PSSession Server01, Server02, Server03 +PS> $s = New-PSSession -ComputerName Server01, Server02, Server03 PS> $jobs = Invoke-Command -Session $s -ScriptBlock {Start-Job -ScriptBlock {Get-Date}} PS> $done = Invoke-Command -Session $s -ScriptBlock {Wait-Job -Timeout 30} PS> @@ -211,7 +211,7 @@ This command uses the job name to identify the job for which to wait. ### Example 8: Wait for jobs on local computer started with Start-Job ```powershell -$j = Start-Job -ScriptBlock {Get-ChildItem *.ps1| where {$_.lastwritetime -gt ((Get-Date) - (New-TimeSpan -Days 7))}} +$j = Start-Job -ScriptBlock {Get-ChildItem -Filter *.ps1| Where-Object {$PSItem.LastWriteTime -gt ((Get-Date) - (New-TimeSpan -Days 7))}} $j | Wait-Job ``` @@ -231,7 +231,7 @@ finishes, the command displays the job object, which contains information about ### Example 9: Wait for jobs started on remote computers by using Invoke-Command ```powershell -$s = New-PSSession Server01, Server02, Server03 +$s = New-PSSession -ComputerName Server01, Server02, Server03 $j = Invoke-Command -Session $s -ScriptBlock {Get-Process} -AsJob $j | Wait-Job ``` diff --git a/reference/7.3/Microsoft.PowerShell.Core/Start-Job.md b/reference/7.3/Microsoft.PowerShell.Core/Start-Job.md index bda5a7be76dc..89572a645fc0 100644 --- a/reference/7.3/Microsoft.PowerShell.Core/Start-Job.md +++ b/reference/7.3/Microsoft.PowerShell.Core/Start-Job.md @@ -220,7 +220,7 @@ This example starts a job that collects a large amount of map data and then save file. ```powershell -Start-Job -Name GetMappingFiles -InitializationScript {Import-Module MapFunctions} -ScriptBlock { +Start-Job -Name GetMappingFiles -InitializationScript {Import-Module -Name MapFunctions} -ScriptBlock { Get-Map -Name * | Set-Content -Path D:\Maps.tif } ``` @@ -235,7 +235,7 @@ This example uses the `$input` automatic variable to process an input object. Us view the job's output. ```powershell -Start-Job -ScriptBlock { Get-Content $input } -InputObject "C:\Servers.txt" +Start-Job -ScriptBlock { Get-Content -Path $input } -InputObject "C:\Servers.txt" Receive-Job -Name Job45 -Keep ``` @@ -309,8 +309,8 @@ Major Minor Patch PreReleaseLabel BuildLabel ``` ```powershell -$job = Start-Job { $PSVersionTable.PSVersion } -PSVersion 5.1 -Receive-Job $job +$job = Start-Job -ScriptBlock { $PSVersionTable.PSVersion } -PSVersion 5.1 +Receive-Job -Job $job ``` ```Output diff --git a/reference/7.3/Microsoft.PowerShell.Core/Stop-Job.md b/reference/7.3/Microsoft.PowerShell.Core/Stop-Job.md index 103c079f81d2..0d9586285337 100644 --- a/reference/7.3/Microsoft.PowerShell.Core/Stop-Job.md +++ b/reference/7.3/Microsoft.PowerShell.Core/Stop-Job.md @@ -2,7 +2,7 @@ external help file: System.Management.Automation.dll-Help.xml Locale: en-US Module Name: Microsoft.PowerShell.Core -ms.date: 12/12/2022 +ms.date: 09/29/2023 online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/stop-job?view=powershell-7.3&WT.mc_id=ps-gethelp schema: 2.0.0 title: Stop-Job @@ -76,7 +76,7 @@ feature. ```powershell $s = New-PSSession -ComputerName Server01 -Credential Domain01\Admin02 -$j = Invoke-Command -Session $s -ScriptBlock {Start-Job -ScriptBlock {Get-EventLog System}} +$j = Invoke-Command -Session $s -ScriptBlock {Start-Job -ScriptBlock {Get-EventLog -LogName System}} Invoke-Command -Session $s -ScriptBlock { Stop-job -Job $Using:j } ``` @@ -168,14 +168,14 @@ selected job. ### Example 7: Stop a job on a remote computer ```powershell -$j = Invoke-Command -ComputerName Server01 -ScriptBlock {Get-EventLog System} -AsJob +$j = Invoke-Command -ComputerName Server01 -ScriptBlock {Get-EventLog -LogName System} -AsJob $j | Stop-Job -PassThru ``` ```Output Id Name State HasMoreData Location Command -- ---- ---- ----------- -------- ------- -5 Job5 Stopped True user01-tablet get-eventlog system +5 Job5 Stopped True user01-tablet Get-EventLog -LogName Sy... ``` This example shows how to use the `Stop-Job` cmdlet to stop a job that is running on a remote diff --git a/reference/7.3/Microsoft.PowerShell.Core/Wait-Job.md b/reference/7.3/Microsoft.PowerShell.Core/Wait-Job.md index 41f3b23ab387..40a945f5d871 100644 --- a/reference/7.3/Microsoft.PowerShell.Core/Wait-Job.md +++ b/reference/7.3/Microsoft.PowerShell.Core/Wait-Job.md @@ -2,7 +2,7 @@ external help file: System.Management.Automation.dll-Help.xml Locale: en-US Module Name: Microsoft.PowerShell.Core -ms.date: 12/12/2022 +ms.date: 09/29/2023 online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/wait-job?view=powershell-7.3&WT.mc_id=ps-gethelp schema: 2.0.0 title: Wait-Job @@ -123,8 +123,8 @@ to determine how many of the jobs are finished. ### Example 3: Determine when the first job finishes ```powershell -$s = New-PSSession (Get-Content Machines.txt) -$c = 'Get-EventLog -LogName System | where {$_.EntryType -eq "error" --and $_.Source -eq "LSASRV"} | Out-File Errors.txt' +$s = New-PSSession -ComputerName (Get-Content -Path .\Machines.txt) +$c = 'Get-EventLog -LogName System | Where-Object {$PSItem.EntryType -eq "error" --and $PSItem.Source -eq "LSASRV"} | Out-File -FilePath Errors.txt' Invoke-Command -Session $s -ScriptBlock {Start-Job -ScriptBlock {$Using:c} Invoke-Command -Session $s -ScriptBlock {Wait-Job -Any} ``` @@ -155,7 +155,7 @@ The fourth command uses `Invoke-Command` to run a `Wait-Job` command in the sess ### Example 4: Set a wait time for jobs on remote computers ```powershell -PS> $s = New-PSSession Server01, Server02, Server03 +PS> $s = New-PSSession -ComputerName Server01, Server02, Server03 PS> $jobs = Invoke-Command -Session $s -ScriptBlock {Start-Job -ScriptBlock {Get-Date}} PS> $done = Invoke-Command -Session $s -ScriptBlock {Wait-Job -Timeout 30} PS> @@ -211,7 +211,7 @@ This command uses the job name to identify the job for which to wait. ### Example 8: Wait for jobs on local computer started with Start-Job ```powershell -$j = Start-Job -ScriptBlock {Get-ChildItem *.ps1| where {$_.lastwritetime -gt ((Get-Date) - (New-TimeSpan -Days 7))}} +$j = Start-Job -ScriptBlock {Get-ChildItem -Filter *.ps1| Where-Object {$PSItem.LastWriteTime -gt ((Get-Date) - (New-TimeSpan -Days 7))}} $j | Wait-Job ``` @@ -231,7 +231,7 @@ finishes, the command displays the job object, which contains information about ### Example 9: Wait for jobs started on remote computers by using Invoke-Command ```powershell -$s = New-PSSession Server01, Server02, Server03 +$s = New-PSSession -ComputerName Server01, Server02, Server03 $j = Invoke-Command -Session $s -ScriptBlock {Get-Process} -AsJob $j | Wait-Job ``` diff --git a/reference/7.4/Microsoft.PowerShell.Core/Start-Job.md b/reference/7.4/Microsoft.PowerShell.Core/Start-Job.md index 6179ddfc280b..bb69f3a5ab1f 100644 --- a/reference/7.4/Microsoft.PowerShell.Core/Start-Job.md +++ b/reference/7.4/Microsoft.PowerShell.Core/Start-Job.md @@ -2,7 +2,7 @@ external help file: System.Management.Automation.dll-Help.xml Locale: en-US Module Name: Microsoft.PowerShell.Core -ms.date: 12/12/2022 +ms.date: 09/29/2023 online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/start-job?view=powershell-7.4&WT.mc_id=ps-gethelp schema: 2.0.0 title: Start-Job @@ -220,7 +220,7 @@ This example starts a job that collects a large amount of map data and then save file. ```powershell -Start-Job -Name GetMappingFiles -InitializationScript {Import-Module MapFunctions} -ScriptBlock { +Start-Job -Name GetMappingFiles -InitializationScript {Import-Module -Name MapFunctions} -ScriptBlock { Get-Map -Name * | Set-Content -Path D:\Maps.tif } ``` @@ -235,7 +235,7 @@ This example uses the `$input` automatic variable to process an input object. Us view the job's output. ```powershell -Start-Job -ScriptBlock { Get-Content $input } -InputObject "C:\Servers.txt" +Start-Job -ScriptBlock { Get-Content -Path $input } -InputObject "C:\Servers.txt" Receive-Job -Name Job45 -Keep ``` @@ -309,8 +309,8 @@ Major Minor Patch PreReleaseLabel BuildLabel ``` ```powershell -$job = Start-Job { $PSVersionTable.PSVersion } -PSVersion 5.1 -Receive-Job $job +$job = Start-Job -ScriptBlock { $PSVersionTable.PSVersion } -PSVersion 5.1 +Receive-Job -Job $job ``` ```Output diff --git a/reference/7.4/Microsoft.PowerShell.Core/Stop-Job.md b/reference/7.4/Microsoft.PowerShell.Core/Stop-Job.md index f0d53b16fee6..950688600c82 100644 --- a/reference/7.4/Microsoft.PowerShell.Core/Stop-Job.md +++ b/reference/7.4/Microsoft.PowerShell.Core/Stop-Job.md @@ -2,7 +2,7 @@ external help file: System.Management.Automation.dll-Help.xml Locale: en-US Module Name: Microsoft.PowerShell.Core -ms.date: 12/12/2022 +ms.date: 09/29/2023 online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/stop-job?view=powershell-7.4&WT.mc_id=ps-gethelp schema: 2.0.0 title: Stop-Job @@ -76,7 +76,7 @@ feature. ```powershell $s = New-PSSession -ComputerName Server01 -Credential Domain01\Admin02 -$j = Invoke-Command -Session $s -ScriptBlock {Start-Job -ScriptBlock {Get-EventLog System}} +$j = Invoke-Command -Session $s -ScriptBlock {Start-Job -ScriptBlock {Get-EventLog -LogName System}} Invoke-Command -Session $s -ScriptBlock { Stop-job -Job $Using:j } ``` @@ -168,14 +168,14 @@ selected job. ### Example 7: Stop a job on a remote computer ```powershell -$j = Invoke-Command -ComputerName Server01 -ScriptBlock {Get-EventLog System} -AsJob +$j = Invoke-Command -ComputerName Server01 -ScriptBlock {Get-EventLog -LogName System} -AsJob $j | Stop-Job -PassThru ``` ```Output Id Name State HasMoreData Location Command -- ---- ---- ----------- -------- ------- -5 Job5 Stopped True user01-tablet get-eventlog system +5 Job5 Stopped True user01-tablet Get-EventLog -LogName Sy... ``` This example shows how to use the `Stop-Job` cmdlet to stop a job that is running on a remote diff --git a/reference/7.4/Microsoft.PowerShell.Core/Wait-Job.md b/reference/7.4/Microsoft.PowerShell.Core/Wait-Job.md index 9bdd1aa749f1..52b9697b3b19 100644 --- a/reference/7.4/Microsoft.PowerShell.Core/Wait-Job.md +++ b/reference/7.4/Microsoft.PowerShell.Core/Wait-Job.md @@ -2,7 +2,7 @@ external help file: System.Management.Automation.dll-Help.xml Locale: en-US Module Name: Microsoft.PowerShell.Core -ms.date: 12/12/2022 +ms.date: 09/29/2023 online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/wait-job?view=powershell-7.4&WT.mc_id=ps-gethelp schema: 2.0.0 title: Wait-Job @@ -123,8 +123,8 @@ to determine how many of the jobs are finished. ### Example 3: Determine when the first job finishes ```powershell -$s = New-PSSession (Get-Content Machines.txt) -$c = 'Get-EventLog -LogName System | where {$_.EntryType -eq "error" --and $_.Source -eq "LSASRV"} | Out-File Errors.txt' +$s = New-PSSession -ComputerName (Get-Content -Path .\Machines.txt) +$c = 'Get-EventLog -LogName System | Where-Object {$PSItem.EntryType -eq "error" --and $PSItem.Source -eq "LSASRV"} | Out-File -FilePath Errors.txt' Invoke-Command -Session $s -ScriptBlock {Start-Job -ScriptBlock {$Using:c} Invoke-Command -Session $s -ScriptBlock {Wait-Job -Any} ``` @@ -155,7 +155,7 @@ The fourth command uses `Invoke-Command` to run a `Wait-Job` command in the sess ### Example 4: Set a wait time for jobs on remote computers ```powershell -PS> $s = New-PSSession Server01, Server02, Server03 +PS> $s = New-PSSession -ComputerName Server01, Server02, Server03 PS> $jobs = Invoke-Command -Session $s -ScriptBlock {Start-Job -ScriptBlock {Get-Date}} PS> $done = Invoke-Command -Session $s -ScriptBlock {Wait-Job -Timeout 30} PS> @@ -211,7 +211,7 @@ This command uses the job name to identify the job for which to wait. ### Example 8: Wait for jobs on local computer started with Start-Job ```powershell -$j = Start-Job -ScriptBlock {Get-ChildItem *.ps1| where {$_.lastwritetime -gt ((Get-Date) - (New-TimeSpan -Days 7))}} +$j = Start-Job -ScriptBlock {Get-ChildItem -Filter *.ps1| Where-Object {$PSItem.LastWriteTime -gt ((Get-Date) - (New-TimeSpan -Days 7))}} $j | Wait-Job ``` @@ -231,7 +231,7 @@ finishes, the command displays the job object, which contains information about ### Example 9: Wait for jobs started on remote computers by using Invoke-Command ```powershell -$s = New-PSSession Server01, Server02, Server03 +$s = New-PSSession -ComputerName Server01, Server02, Server03 $j = Invoke-Command -Session $s -ScriptBlock {Get-Process} -AsJob $j | Wait-Job ```