cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
639
Views
0
Helpful
2
Replies

connect-ucs script not working

Dragomir
Level 1
Level 1

when i run the below script, it does not log me into ucs, I checked it with get-ucspssession and there was nothing. but if I manually type in the command one line at a time, it works. any idea why?

set-ucspowertoolconfiguration -supportmultipledefaultucs $true

$ucs1 = @("ucsa", "ucsb", "ucsc)

$ucs2 = @("ucsd")

$ucs3 = @("ucse")

$ucsadmin = "admin"

$ucspass1 = "xxxxxxx" | ConvertTo-SecureString -AsPlainText -Force

$ucspass2 = "yyyyyyy" | ConvertTo-SecureString -AsPlainText -Force

$ucspass3 = "zzzzzzz" | ConvertTo-SecureString -AsPlainText -Force

$ucscreds1 = New-Object System.Management.Automation.PSCredential($ucsadmin, $ucspass1)

$ucscreds2 = New-Object System.Management.Automation.PSCredential ($ucsadmin, $ucspass2)

$ucscreds3 = New-Object System.Management.Automation.PSCredential ($ucsadmin, $ucspass3)

login to UCS

Write-Host "UCS: Logging into UCS Domain: $ucs1, $ucs2, $ucs3"

connect-ucs $ucs1 -credential $ucscreds1

connect-ucs $ucs2 -credential $ucscreds2

connect-ucs $ucs3 -credential $ucscreds3

2 Replies 2

nveda
Level 1
Level 1

Hi Tony,

Script runs in local scope so you will not be able to see output in Get-UcsPsSession.

Try running your script in following way. Using Dot Source Notation with Scope.

PS C:\> . 'C:\Work\MultipleUcs\multipleucs.ps1'

Below are some links which can help in understanding scope.

http://www.howtogeek.com/203778/how-scopes-affect-powershell-scripts/

http://powershell.com/cs/blogs/ebookv2/archive/2012/03/19/chapter-12-command-discovery-and-scriptblocks.aspx

https://technet.microsoft.com/en-us/library/hh847849.aspx

Let us know if above helps.

Thank you,

Nitin

Though what Nitin says is true, that does not appear to be the cause of this issue.  I created the script and ran it in my environment and found the same thing - only I put the Get-UcsPsSession into the script so I could see the session information.  As the script is written, it does not return anything.

However, if you remove the Set-UcsPowerToolConfiguration from the script (and leave the Get-UcsPsSession in the script), you will see that things work fine.

Not sure why the Set-UcsPowerToolConfiguration cmdlet is causing that to happen, but it is a global setting.  That is, you do not have to do in every script.

Cisco UCS X-Series Energy Efficiency Offer