0

I have difficulties troubleshooting scriptblock used in start-job.

Basically I wanted to get WMI properties for servers. If I issue the following command from Powershell, it works.

c:/>$wmi=Get-WmiObject -class Win32_OperatingSystem -computer servername

However, if I run the command in scriptblock of start-job, the job runs forever.

c:/> start-job -argumentList servername -scriptblock {$wmi=Get-wmiobject 
-class win32_operatingsystem -computer $args[0]}

C:/> get-job
Id   Name    State     HasMoreData   Location    Command
--   ----    -----     -----------   --------    -------
169  Job169  Running   True          localhost   $wmi=Get-WmiObject -cl...

Any help or suggestions is much appreciated.

Thanks

Barry Chum
  • 829
  • 3
  • 14
  • 23

1 Answers1

1

Is this on Windows XP? There is a known issue with WMI on Windows XP and Start-Job. Read this thread: WMI Query Script as a Job

This could be due to corrupt WMI repository. Try rebuilding it once.

Community
  • 1
  • 1
ravikanth
  • 24,922
  • 4
  • 60
  • 60
  • yes, it is on XP. Really appreciate your information. I've never thought of this is a issue with WMI on XP!!! – Barry Chum Sep 06 '12 at 08:23
  • I followed the instructions given in the link to rebuild the repository but didn't fix. However, the start-job command worked on a Win2003 server!!! – Barry Chum Sep 06 '12 at 10:07