PowerShell to Automate Cisco UCSM (2): PowerGUI Editor


I introduced how to set up the UCSM automation lab and used PowerTool, the Cisco PowerShell module, to connect and manage UCSM (see PowerShell to Automate UCS (1): Lab Setup).

This blog is to introduce my favourite PowerShell editor, PowerGUI, which provides an intuitive graphic interface, simplifies scripting work and allows easy test and troubleshooting. Most importantly it is free!

Download PowerGUI from DELL (It is now owned by DELL): http://software.dell.com/products/powergui-freeware/

PowerGUI 3.8 is used in this lab. The lab steps are as below:

Step 1: Install PowerGUI on Windows

Nothing fancy, just follow the installation wizard and click though.

Step 2: PowerGUI Administrative Console

After successfully install PowerGUI, two programs are installed ‘PowerGUI Administrative Console‘ and ‘PowerGUI Script Editor‘. I am not going to elaborate ‘PowerGUI Administrator Console’ in this blog. However, if you need to add a PowerShell library such as AD snap-in to manage Active Directory (get-aduser, adgroup etc. commands are unavailable if not install the library), you will need to use ‘PowerGUI Administrative Console’ as below and add through ‘File > PowerShell Libraries…’.


Step 3: PowerGUI Script Editor

‘PowerGUI Script Editor’ is the tool we are using to write PowerShell script. The window should be as below:


1 – Create new script

2 – Script browser

3 – Script editing area

# starts comments, and is shown in Green in the editor.

Command is shown in Aqua such as ‘import-module’. PowerGUI also provides command hint as below. Move mouse pointer over a command, it will reveal the command syntax.


Variables are in purple. After executing the script once, variable values are shown in ‘4 Variables’, which I found useful in troubleshooting whether values are parsed as required.

4 – Variables used in script

This area shows default and user-defined variables and the value stored. Arrange is also supported in PowerShell, we will come to it in the next blog. Variable type is not normally required in PowerShell; though it can be define via [string] [int] and etc. in front of a variable. For example,the following is a string:

[string]$var = 5

$ to indicate a variable is followed; = to assign value to variable; “” to indicate string as value; while numerical value is assgined without “”. For example, the first one is a string; the second is an integer.

$password = "ucspe"
$number = 5

5 – Execute script

The result will be shown in ‘7 – Script execution result’.

6 – Script execution status

Whether the execution is completed.

7 – Script execution result

If the script completes successfully, the result will show here; if the script fails to run, debug information will show. Our result from ‘get-ucsstatus’ is as below:

Proxy :
VirtualIpv4Address :
HaConfiguration : cluster
HaReadiness : ready
HaReady : yes
EthernetState : full
ChassisSerial1 : CH1
ChassisSerial2 : CH2
ChassisSerial3 : RK1
Chassis1Status : ok
Chassis2Status : ok
Chassis3Status : ok
FiALeadership : primary
FiAManagementServicesState : up
FiAOobIpv4Address :
FiAOobIpv4DefaultGateway :
FiAOobIpv4SubnetMask :
FiBLeadership : subordinate
FiBManagementServicesState : up
FiBOobIpv4Address :
FiBOobIpv4DefaultGateway :
FiBOobIpv4SubnetMask :

We can also select certain attribute instead of retrieve everything using ‘get-ucsstatus’. We now change the command to:

get-ucsstatus | select VirtualIpv4Address

The result will be as below:

VirtualIpv4Address :

Is it similar to SQL syntax? Yes, and PowerShell support ‘where’ to define condition as well!

Today’s PowerTool Script

Today’s full script is as below:

#clear screen.

#Import Cisco UCS PowerTool module into PowerShell.
Import-Module CiscoUcsPS

#Define variables.
$ucsvip= ""

#Auto logon UCSM, credentials are not manually input into the pop-up window anymore (see PowerShell to Automate UCS (1): Lab Setup).
$user = "ucspe"
$password = "ucspe" | ConvertTo-SecureString -AsPlainText -Force
$cred = New-Object system.Management.Automation.PSCredential ($user,$password)
Connect-Ucs $ucsvip -Credential $cred

#Retrieve the current UCS stauts to verify the logon was successful.

#Disconnect the connection to UCSM.

To be continued

In today’s lab, PowerGUI is used as PowerShell editor to write and test scripts. The script connects to the UCSM built in PowerShell to Automate UCS (1): Lab Setup and retrieves UCSM status.

Future blogs will introduce more useful scripts and tricks.

Learning by doing; doing by learning…reading and thinking alone won’t make fast learner, that’s why I am writing these lab blogs.

Next: PowerShell to Automate UCS (3): Convert UCSM GUI to Script



3 thoughts on “PowerShell to Automate Cisco UCSM (2): PowerGUI Editor

  1. Pingback: PowerShell to Automate UCS (1): Lab Setup | MengMeng

  2. Pingback: PowerShell to Automate UCS (3): Convert UCSM GUI to Script | MengMeng

  3. Pingback: PowerShell to Automate UCS (4): PS with .Net to develop UI and provision service profile | MengMeng

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s