1

So, I have been trying to do the following via a PowerShell script:

For a list of computers, do:

  • Ping the computer (via WMI) to see if it's available; if not, log & break, if so, continue on
  • Create a folder on the root of the C:\ drive (via Invoke-WmiMethod); if fails, log & break, if successful, continue on
  • Copy files (includes an .exe) from another machine into that folder; if fails, log & break, if successful, continue on
  • Run the .exe file (via Invoke-WmiMethod); if fails, log & break, if successful, log success, done (with this computer.)

The problem I'm running into is the execution of the .exe (program installer) -- the Invoke-WmiMethod command usually works, but for some machines, it hangs (not fails, but hangs.) I've tried a whole bunch of stuff to try to get it to run as a job so I can set a timeout on the install (running the Invoke-WmiMethod command with -AsJob param, always returns Failed...; Start-Job -Computer $compname { Invoke-WmiMethod..., returns Completed but the install never happens; making sure the remote machines have Windows Firewall disabled, UAC turned off, etc. but still if I run the Invoke-WmiMethod command on them, not running as a job, it hangs. And yes, I'm running PS as a Domain Admin, so I should have rights on the target machines.)

So being a newb at all things PowerShell, I'm now at a complete loss as to what to try next... How would you tackle running a .exe on a remote system from a PowerShell script? One caveat is that the target machines don't all run PowerShell [V1|V2] (target PCs are a mix of XP, Vista and 7) or don't have remoting enabled. The other caveat being that the installer is an .exe, and not an .msi, and this can't be changed (it's a third-party app.)

Thanks in advance to anyone who can point me in the right direction here (and give me some sample code...)

Will Dennis
  • 613
  • 2
  • 13
  • 24
  • Do you have WinRM installed on all the machines? What would be the chances of getting these machines upgraded to PowerShell 2.0? – Kev Apr 01 '11 at 12:53

1 Answers1

1

What OS is running on the system (management station or central system) where these scripts are getting executed? If Windows XP, there is a known issue with WMI and -asJob.

Check this: WMI Query Script as a Job

In such a case, I'd suggest moving to a Windows 7 system and then run the script to remotely install .exe on all other machines.

Community
  • 1
  • 1
ravikanth
  • 24,922
  • 4
  • 60
  • 60
  • Hi Ravikanth - the script is being run on a Windows 7 system... My test targets that are hanging happen to be Win Vista machines (so far.) – Will Dennis Mar 30 '11 at 02:31
  • Interesting! Did you try something like PSEXEC? I have an example at http://www.ravichaganti.com/blog/?p=1888. – ravikanth Mar 30 '11 at 05:58
  • Yes, that was my thought. We have a quick-n-dirty batch script that does the four steps (on one PC) and it uses PsExec, and it works. Anyways, I'm trying to modify the script you linked, and the `Get-PSCredential` function is blowing up with `Cannot bind argument to parameter 'String' because it is an empty string.` (converting the $password variable.) ??? – Will Dennis Mar 30 '11 at 15:42
  • Never mind, I just used `Get-Credential` to set a $cred variable, and am using that in place of the `Get-PSCredential` function. – Will Dennis Mar 30 '11 at 16:05
  • @Kev, I'm in process of rolling out PowerShell v2 via SUS, and have authored a GPO policy to allow remoting. But, knowing our loose environment, I'm sure we won't get 100% rollout (60-70% I'd guess at best...) So a solution that doesn't depend on PSv2/WinRM would be best. – Will Dennis Apr 05 '11 at 03:36