PowerShell: Encapsulating Function Inside a Function and Inside an Invoke-Command or Job

$domain='google.com'

function pingSomething($x){
    $result=ping $x
    function getTraceroute($y){
        pathping $y
    }
    $result+=getTraceroute $x
    return $result
}

$job=Start-Job -ScriptBlock {
    param($importedFunction,$params)
[ScriptBlock]::Create($importedFunction).invoke($params)
} -Args ${function:pingSomething},$domain
    
Wait-Job $job|out-null 
Receive-Job $job  

Leave a Reply

Your email address will not be published. Required fields are marked *