What am I doing wrong? Why can’t I get the parameter to pass though?
Write-Output $value, does issue the proper value, but for some reason it is not liked in the second script. I would think that this should be super simple, but it is driving me mad.
When you call out to powershell.exe, all of your variables are basically converted to strings. Since you’re already in powershell, why not just call Invoke-Command directly?
I’m wondering, like Dave, why the call to powershell.exe inside of powershell. Aside from that, I don’t think you can pass parameters to powershell.exe’s -Command script block. You can build a string like so:
That’s odd. I didn’t think your local ExecutionPolicy should matter to Invoke-Command. I wonder if that’s a bug, maybe you can get around it like this:
Invoke-Command : Cannot bind parameter ‘ScriptBlock’. Cannot convert the “My script contents” value of type “System.String” to type “System.Management.Automation.ScriptBlock”.
At E:\script.ps1:9 char:29
invoke-command -ScriptBlock $scriptContent -computername server -argumentlist …