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

PowerShell: Obtain List of Hyper-V Hosts in All Domains of All Forests

Version 0.03: https://blog.kimconnect.com/powershell-obtain-list-of-hyper-v-hosts-via-active-directory/ Version 0.02: https://blog.kimconnect.com/powershell-get-nic-mtus-of-all-hyper-v-hosts-in-domain-forest/ Previous version: # listHyperVHostsInForests.ps1# version 0.01# This function scans…

How To Use Command Line to Configure iDrac Settings

Step 1: Install RacADM $computerlist=@' SERVER1 SERVER2 '@ $computernames=@($computerlist -split "`n")|%{$_.Trim()} $fileURL="https://dl.dell.com/FOLDER08543783M/1/DellEMC-iDRACTools-Web-WINX64-10.3.0.0-4945.exe" $expectedExecutable='racadm.exe' $expectedInstallPath='C:\Program Files\Dell\SysMgt\iDRACTools\racadm'…

Script to use WinRAR for backups

REM winrar_backup.batecho offSET FNAME=KIMCONNECTSET LOGFILE=\\FILESERVER01\backup\ads-02-backup.txtIF EXIST V:\ (NET USE V: /DELETE)net use v: \\FILESERVER01\backupIF %ERRORLEVEL%…