Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

PowerShell Scoping and ScriptBlocks

$
0
0

PowerShell scoping has defeated me again.  Why does the code below return a null value instead of "blah"?  How can I make it return "blah"?

$string = "blah"
$Session = New-PSSession -ComputerName "RandomRemoteComputer"
Invoke-Command -Session $Session -ScriptBlock{$string}

I have tried it with the global scope specified on all variables.  Same exact result.


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>