Logged in to the system directly, I run this statement, and get this output:
(Get-ClusterNetwork 'cluster backups').role
None
This is perfect... beautiful even, in it's simplicity.
However, when I run the exact same statement from a remote machine using invoke-command, which up until now i always just assumed was like typing this exact statement into the CLI of the machine, I get THIS output instead
Invoke-Command -Session $hi -ScriptBlock {(Get-ClusterNetwork 'cluster backups').role}
PSComputerName RunspaceId Value
-------------- ---------- -----
dumdum a84b6c89-dumdum-80d3-ed43230ee8ab None
Now here's the really funny thing. If i assign a variable to the invoke-command output, it'll have the same output shown above UNLESS - i pipe it to set-clipboard
So the variable
$hello = invoke-command -session $hi -scriptblock {(get-networkcluster 'cluster backups').role}
Now type $hello into prompt and I get:
PSComputerName RunspaceId Value
-------------- ---------- -----
dumdum a84b6c89-dumdum-80d3-ed43230ee8ab None
Which is expected. But now when I pipe that to set-clipboard and paste - the value is:
$hello | set-clipboard;
get-clipboard
None
Which is the actual value I want. Somehow piping to set-clipboard knows to only pull the property that i originally asked for. Even though the variable, has all the properties. When i run $hello.gettype() - i see the value as Int32. Which makes sense if $hello was only returning the value I wanted, but it's... not.
But if that wasn't weird enough - I'm running a few functions within the invoke-command, this is only one piece - all of the functions return a value i'm trying to report on. So:
$row = '' | select computername, ClusterNetworkRole, IP;
$row.computername = $name;
$row.clusternetworkrole = $hello;
$row.ip = dum.dum.dum.dum;
Return $row;
Do you know what the output of $row.clusternetworkrole is? Take a wild guess. It's every property EXCEPT the one I want.
$row
PSComputerName : dumdum
RunspaceId : b898bdad-dumdum-9eff-8a2beeefe78a
ClusterNetworkRole :
Computername : dum
IP : dum.dum.dum.dum
Not only does it give me the exact properties i DON'T want - it actually adds those properties as members of $row.
$row.RunspaceID
b898bdad-dumdum-9eff-8a2beeefe78a
Now i can get the value i want by appending ".value" at the end of the statement, so this isn't so much a problem to be solved as much as it is a question of just what the hell powershell is doing. It's taken this simple, beautiful tiny statement - and wreaked havoc on my life.