Time out on certain cmdlets

This topic contains 4 replies, has 3 voices, and was last updated by  Sam Boutros 3 weeks, 4 days ago.

  • Author
    Posts
  • #92123

    Sam Boutros
    Participant

    Is there a way to put a time out on certain cmdlets like Get-NetIPAddress and GetProcess?

  • #92126

    Don Jones
    Keymaster

    Only if the cmdlet directly supports it via a parameter.

    • #92141

      Sam Boutros
      Participant

      Well, what I've done in similar situations in the past is find the underlying WMI call for example, and write a function that would provide things the native cmdlet does not like time-out. I try to not write proxy functions for obvious reasons..
      For example,

      Install-Module SB-Tools,POSH-SSH -Force
      Import-Module SB-Tools -DisableNameChecking
      (Get-Command Get-SBWMI).Definition
      

      will show the Get-SBWMI function which provides a TimeOut parameter

      I was hoping someone has done that already..

    • #92149

      Patrick Meinecke
      Participant

      For CIM based commands you can use a cimsession with a timeout

      $cimSession = New-CimSession -OperationTimeoutSec 1
      Get-NetIPAddress -CimSession $cimSession
      

      Not in general though.

    • #92155

      Sam Boutros
      Participant

      Thanks Patrick, I think this works, I'll try it..

You must be logged in to reply to this topic.