Forum Discussion

Benson01_160074's avatar
Benson01_160074
Icon for Nimbostratus rankNimbostratus
Jul 16, 2014

Disconnect iControl if user is idle?

Powershell script:

 

Initialize-F5.iControl -hostname 'xxx.xxx.xxx.xx' -credentials (Get-Credential) Read-Host 'Input' User idles and never enters an input while ($true) { Never reaches here }

 

If the script hangs at Read-Host for, say, 10 minutes, I want my script to stop working. I want to either exit the script, or uninitialize the F5 connection. Is there any way to do this? Read-Host doesn't appear to have a timeout option. I have also looked at LocalLBProfileTCP methods (such as set_idle_timeout) without success.

 

2 Replies

  • For some reason the edit button isn't working...

    Initialize-F5.iControl -hostname 'xxx.xxx.xxx.xx' -credentials (Get-Credential) 
    Read-Host 'Input'  User idles and never enters an input 
    while ($true) { 
         Never reaches here 
    }
    
  • There is no "persistent" connection with iControl. When you call "Initialize" with credentials, it tests a connection with those creds and, if that succeeds, caches them locally in the internal iControl.Interfaces object (returned from the Get-F5.iControl cmdlet). All calls to the BIG-IP are separate HTTPS connections with independent authorization so there really isn't anything to "disconnect".

    If you want to "uninitialize" the Interfaces object, you can do something like this

    (Get-F5.iControl).ConnectionInfo.creds.UserName = ""

    And then subsequent calls will fail with a 401 Authorization required error until you call Initialize-F5.iControl again.

    As for a timed input prompt, Read-Host doesn't support that. Do a search for "powershell read-host timeout" and there are some solutions out there for rolling your own.

    -Joe

    -Joe