control output remoting script

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of Bin Ary Bin Ary 12 months ago.

  • Author
  • #31261
    Profile photo of Bin Ary
    Bin Ary

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

    Function TASKS {....}
    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

  • #31492
    Profile photo of Adam Platt
    Adam Platt


    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!


  • #31514
    Profile photo of Bin Ary
    Bin Ary

    thank you

You must be logged in to reply to this topic.