title: Timeout Get-WMIObject cmdlet
body: <p>I run a script which performs many WMI-querys - but the cmdlet hangs if the server doesn't answer..
  Is there any way I can make this (or any other cmndlet for that matter) timeout and exit if X seconds has passed?</p>
  
  <p><strong>Edit</strong></p>
  
  <p>Thanks to a tip from mjolinor the solution is to run this as -asjob and set a timeout in a while loop. But this is run from within a job already (started with Start-Job). So how do I know I am controlling the correct job?</p>
  
  <p>This is my code from inside my already started job:</p>
  
  <pre><code>Get-WmiObject Win32_Service -ComputerName $server -AsJob
  
  $Complete = Get-date
  
  While (Get-Job -State Running){
      If ($(New-TimeSpan $Complete $(Get-Date)).totalseconds -ge 5) {
          echo "five seconds has passed, removing"
          Get-Job  | Remove-Job -Force
      }
      echo "still running"
      Start-Sleep -Seconds 3
  }
  </code></pre>
  
  <p>PS: My jobs started with Start-Jobs are already taken care of..</p>