How to add -AsJob feature to user defined functions?

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of  Anonymous 2 years ago.

  • Author
    Posts
  • #25296
    Profile photo of
    Anonymous

    Hi,
    Firstly,
    Could someone help me to add ' -AsJob ' powershell feature to my functions which I wrote in the below general format.

    Function Verb-Noun
    {
       [CMDLetBinding()]
       Param(
          $Parameter
       )
       BEGIN{}
       PROCESS{}
       END{}
    }
    

    Secondly,
    How to know any job's progress of completion and from how long time its been running?

  • #25299
    Profile photo of Don Jones
    Don Jones
    Keymaster

    You can't tap into the job system that easily. To have that work exactly as the native commands, you'd have to code your own job type, which ant be done in script.

  • #25304
    Profile photo of
    Anonymous

    Thnx for your information. Have you discussed how to write it in an any text book? or videos?
    I have Powershell In Depth text book.

    $CallThisText = 'Get-HealthCheck.ps1 -Server '+$Batch[$i]
    							$StartInfo = New-Object System.Diagnostics.ProcessStartInfo
    							$StartInfo.FileName = "C:\Windows\System32\WindowsPowerShell\V1.0\PowerShell.exe"
    							$StartInfo.Arguments="-NoExit -Command `"$CallThisText`" "
    							$StartInfo.LoadUserProfile = $True
    							$StartInfo.UseShellExecute = $True
    							$StartInfo.WorkingDirectory = (Get-Location).Path
    							$proc = [System.Diagnostics.Process]::Start($StartInfo)
    

You must be logged in to reply to this topic.