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

Basic CSS: Change the Color of Text

<h2>CatPhotoApp</h2><main> <p>Click here to view more <a href="#">cat photos</a>.</p> <a href="#"><img src="https://bit.ly/fcc-relaxing-cat" alt="A cute orange…

PowerShell: Get Terminal Service (Remote Desktop Service) Licenses Report

# rdsLicenseReport.ps1 $knownRdsComputers=$null # Options: (a) 'SERVER1','SERVER100' (b) Get-Content Path\To\RDServers.txt function getTsLicenses{ param( $knownRdsComputers, $domain=$env:userdnsdomain…

PowerShell: Compressing Files and Folders

# Set variables $compressTarget="C:\Temp\Win2016_Std_Template.ova" $parentFolder=split-path $compressTarget -Parent $grandParentFolder=split-path $parentFolder -Parent $compressedFile=$grandParentFolder+"\compressed.zip" # PowerShell version 5…