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
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.