cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
955
Views
3
Helpful
5
Replies

PowerShell Support for UCS

I have written the script below. The problem I am receiving is, after a period of time I am no longer receiving input, and when I attempt to manually login to the UCS Manager I get the following error, "Login Error: Failed login info: User reached maximum session limit" The script is meant to connect to the UCS and return the faults. It runs for about 30 - 45 minutes and then just stops connecting. I have not included the function to obtain the UCS Credentials. This functions works, so if I fat fingered something I apologize ahead of time. I believe the issue has to deal with closing the session. The function that is not listed below merely creates a PSCredential object that stores user name and password information to pass to the function below.

########################################################

Function ucsFaultCheck ($ucsCred)

{

# set UCS handle (#.#.#.# = redacted ip)

$ucsHandle = Connect-Ucs #.#.#.# -NotDefault -Credential $ucsCred

# get UCS faults and store in variable

$ucsResults = Get-UcsFault -Ucs $ucsHandle | ? {$_.Severity -ne 'info'} | Sort-Object -Property Severity -Descending | Select-Object Severity, @{Name="Created"; Expression={$_.Created.substring(0,10)}}, @{Name="Description"; Expression={$_.Descr}}

# disconnect from UCS session

Disconnect-Ucs

# return results

$ucsResults

} # END Function ucsFaultCheck

5 Replies 5

Walter Dey
VIP Alumni
VIP Alumni

This is a common behaviour; if sessions are not terminated properly, they hang around for quite some time, and you run into this problems.

See attachment; you can delete this orphans and then it will work again.

Walter, that is good information, but I thought Disconnect-Ucs was how to properly terminate the session. Is there a better way for me to terminate the session so that I don't build multiple sessions over time? Could I do something like "Disconnect-Ucs $ucsHandle"?

I agree with you ! I tried several things

- Exit UCS Manager (you are asked, exit or logoff manager) -> session is correctly terminated

- just close browser -> session is correctly terminated

I remember testing PS scripts, ending up with dozens of sessions.

Did you test, if disconnect UCS doesn't terminate the session properly ?

So, I ran the script today and verified it isn't closing the session and I ran it from PowerShell as individual commands and again it didn't disconnect. I am going to attempt to create the $ucsHandle in the ucsPass function and just pass the $ucsHandle into the function above. This should reuse the same session. I don't know if there is a period of time that a session will stay open before timing out, but Disconnect-Ucs does not terminate the session.

Details:

OS: Windows 7

Java: 7 Update 25

UPDATE: The fix below works to an extent. It still doesn't terminate the session. So, the question remains.. How do you properly terminate a session, because "Disconnect-Ucs" does not work.

Answer: Have the function that creates the credentials, also create the UCS handle. Then pass the handle to the function that does your request, and it will reuse the same session without creating a new one. See below.

########################################################

Function ucsHandle ()

{

$ucsUser = "admin"

$ucsPassName = "***Encrypted password redacted***"

#check current user and apply password if applicable (this runs without prompting the user for credentials

if ($env:username -eq "user.name")

{ $ucsCred = New-Object -TypeName System.Management.Automation.PSCredential -argument $ucsUser, ($ucsPassName | ConvertTo-SecureString) }

# if not specified user prompt for credentials

else { $ucsCred = Get-Credential }

# set Cisco UCS Credential

$ucsHandle = Connect-Ucs X.X.X.X -NotDefault -Crednetial $ucsCred

# return Cisco UCS Handle

$ucsHandle

} # END Function ucsHandle

########################################################

Function ucsFaultCheck ($ucsHandle)

{

# get UCS faults and store in variable (There is some formatting of the fields, and which fields to return)

$ucsResults = Get-UcsFault -Ucs $ucsHandle | ? {$_.Severity -ne 'info'} | Sort-Object -Property Severity -Descending | Select-Object Severity, @{Name="Created"; Expression={$_.Created.substring(0,10)}}, @{Name="Description"; Expression={$_.Descr}}

# return results

$ucsResults

} # END Function ucsFaultCheck

Review Cisco Networking products for a $25 gift card