invoke-command, powershell 2.0 equivalent??

I’ve got an executable which runs with arguments which I need to run on multiple PCs.
This code obviously does not work but it shows the commands.
\$computer\C`$\temp\snetcfg.exe -v -c s -u MS_Server
\$computer\C`$\temp\snetcfg -v -l \$computer\C`$\windows\inf\netserv.inf -c s -i MS_Server

  1. should I copy the *.exe file into C:\temp and if so how would I run it from c:\temp on all the computers??
    OR
  2. can I run this *.exe with arguments from a remote file share??

Basically I need to run this in PS 2.0 but most of what I find for this is invoke-command which I believe is not in PS 2.0…

Thank you, Tom

PSRemoting (and Invoke-Command) were added in PowerShell 2.0, so that shouldn’t be a problem. Once you’ve pushed out your exe file, you’d just convert your UNC paths into the equivalent local paths, and do something like this:

$scriptBlock = {
    c:\temp\snetcfg.exe -v -c s -u MS_Server
    c:\temp\snetcfg -v -l c:\windows\inf\netserv.inf -c s -i MS_Server
}
Invoke-Command -ComputerName $computer -ScriptBlock $scriptBlock

As long as you don’t run into the “second hop” problem (which you can read about all over the place by searching for that term), this should probably work.

OIC – thank you for clarifying.
I had also been doing the syntax etc. all wrong.
I will now test this!! :slight_smile: :slight_smile:
Thank you, Tom

Am I getting this error because of the double-hop issue??
The firewall exceptions are enabled.

[MLS-LT-207] Connecting to remote server MLS-LT-207 failed with the following error message : WinRM cannot complete the operation. Verify that the
specified computer name is valid, that the computer is accessible over the network, and that a firewall exception for the WinRM service is enabled and
allows access from this computer. By default, the WinRM firewall exception for public profiles limits access to remote computers within the same local
subnet. For more information, see the about_Remote_Troubleshooting Help topic.
+ CategoryInfo : OpenError: (MLS-LT-207:String) , PSRemotingTransportException
+ FullyQualifiedErrorId : WinRMOperationTimeout,PSSessionStateBroken

Is there any other way to run these commands on the remote computers??

Thank you, Tom

Nope, that’s just a “can’t connect with PSRemoting” error. Have you run Enable-PSRemoting on the remote systems?