How to add -AsJob feature to user defined functions?

Welcome Forums General PowerShell Q&A How to add -AsJob feature to user defined functions?

This topic contains 2 replies, has 2 voices, and was last updated by

 
Inactive
3 years, 8 months ago.

  • Author
    Posts
  • #25296

    Inactive
    Points: 0
    Rank: Member

    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

    Keymaster
    Points: 1,785
    Helping HandTeam Member
    Rank: Community Hero

    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

    Inactive
    Points: 0
    Rank: Member

    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)
    

The topic ‘How to add -AsJob feature to user defined functions?’ is closed to new replies.