Posted On June 17, 2020

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

kimconnect 0 comments
blog.KimConnect.com >> Codes >> 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 *

Related Post

How to Use Google SMTP Relay with Sendmail

Check to see if TLS is enabled:# sendmail -d0.1 -bv rootMake a certs directory:# mkdir…

Linux: How to Set Startup Script

In previous Linux versions, startup scripts can simply be enabled by linking a script into…

PowerShell: Generate a CSV Report of O365 Exchange Online Mailboxes

# Office 365 Global Admin Credential$username="[email protected]"$password=ConvertTo-securestring "PASSWORD" -AsPlainText -Force$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $username,$passwordfunction…