05-12-2015 09:05 PM
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
05-13-2015 01:22 AM
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/
https://technet.microsoft.com/en-us/library/hh847849.aspx
Let us know if above helps.
Thank you,
Nitin
05-13-2015 07:01 AM
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.
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide