Functions/Test-LoopFunction.ps1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
Function Test-LoopFunction { <# .SYNOPSIS This function will loop through a job and return to the console when the job is done. .DESCRIPTION This function will loop through a job and return to the console when the job is done. .PARAMETER JobID This should be the ID of the job to monitor. .INPUTS None .OUTPUTS This Outputs a simple Done when it is done. .NOTES Version: 1.0 Author: Lars Petersson Creation Date: 2019.072.09 Purpose/Change: Initial script development .EXAMPLE Test-LoopFunction -JobID 3 .EXAMPLE Test-LoopFunction -JobID $StartJob.id #> [CmdletBinding()] Param( [Parameter(Mandatory,ValueFrompipeline=$True)][string]$JobID ) DO { $JobLoop = Get-Job -ID $JobID Write-Verbose "$($JobLoop)" IF($JobLoop.State -eq "Running") {"Cogitating";Sleep 5} } While ($JobLoop.State -eq "Running") "Done" $JobLoop } |