Training and Invoke-Command

I’ve finally signed up for MS 50025A. I know that soon it will be outdated. But to be honest I really want to finally get some training in PS area. I know how valuable it can in opposite to reading articles/ books – I’ve seen it with VBS. It will be in June, so I should have TFM already. But I guess I will take course first and move on with the book soon after.

Today I finished my script for 4th event, PS, advanced. And my main problem was remoting – I know very little about it and had some serious problems with forcing it to use my variables when invoke-command some .NET class static method. I first tried:

Invoke-Command -Session $Session { [Environment]::GetEnvironmentVariable($Name, $Target) }

And got only error. So I search on similar problems found few suggestions, neither worked, got frustrated… 😉

Finally I came across this article: How to pass arguments for remote commands on Windows PowerShell BLog. And – man – it became so obvious when I read it. I decided that (param) statement is to much for my needs so all I need to do was:

Invoke-Command -Session $Session -Args $Name, $Target { [Environment]::GetEnvironmentVariable($Args[0], $Args[1]) }

Sweet and simple. Now to the next event of:



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s