Author Posts

October 23, 2015 at 10:43 am

hello
i have a function that do a lot of tasks running remotely on multiple computers

Function TASKS {....}
IPS=@(IP1,IP2,...IPN) 
ICM IPS ${Function:TASKS}

the function work on each computer but I want to end the output of each task on my central console with:
......
This task executed on: IP1
....
This task executed on: IP2

in other words.. is it possible to get IP from wich my task is executed.., when i used argumentlist parameter i have the same IP value on the output
thank you

October 29, 2015 at 10:55 am

Hi,

Any values that are output from your TASKS function as it runs on an individual remote machine will be received in the pipeline of the machine you're running from. That means you could add, for example Write-Output $env:COMPUTERNAME to the end of the code in the TASKS function, and then modify your Invoke-Command like this:

ICM $IPS ${Function:TASKS} | ForEach-Object {
    Write-Host "This task executed on: $_"
}

The reason I did it with the computer name instead of the IP is because it's easier. You can get the IP of the machine like this:

(get-netadapter | get-netipaddress | ? addressfamily -eq 'IPv4').ipaddress

Hope that helps!

-Adam