control output remoting script

This topic contains 2 replies, has 2 voices, and was last updated by  Bin Ary 1 year, 10 months ago.

  • Author
    Posts
  • #31261

    Bin Ary
    Participant

    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

  • #31492

    Adam Platt
    Member

    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

  • #31514

    Bin Ary
    Participant

    thank you

You must be logged in to reply to this topic.