Time out on certain cmdlets

Welcome Forums General PowerShell Q&A Time out on certain cmdlets

This topic contains 4 replies, has 3 voices, and was last updated by

 
Participant
9 months, 3 weeks ago.

  • Author
    Posts
  • #92123

    Participant
    Points: 59
    Rank: Member

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

  • #92126

    Keymaster
    Points: 1,619
    Helping HandTeam Member
    Rank: Community Hero

    Only if the cmdlet directly supports it via a parameter.

    • #92141

      Participant
      Points: 59
      Rank: Member

      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

      Participant
      Points: 35
      Rank: Member

      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

      Participant
      Points: 59
      Rank: Member

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

The topic ‘Time out on certain cmdlets’ is closed to new replies.