Tuesday, May 26, 2015

PowerShell Invoke-Command with -computername object/hash/array

Note to Self:

When using Invoke-Command -ComputerName $nodes.ComputerName, write the scriptblock such that the computername is echoed with the result.

Invoke-command -ComputerName $nodes.ComputerName -Credential $mycred -ScriptBlock {"$ENV:ComputerName, $(test-path D:\folder\file)"}


This will ensure you get the answer at the same time as the computername.  All other attemps are problematic, and test-path doesn't automatically trigger the ComputerName field in the returned dataset.



No comments: