Microsoft Powershell is a complex automation tool that can be used across platforms. It can be used in different ways, as a command-line shell, where provides convenient features such as command-line history, or support for command and parameter aliases and command pipelining. It can be used as a scripting language, as a component of a CI-CD pipeleine, where it can be used for the automation of management systems by supporting common data formats like CSV, JSON and XML. Powershell is also a powerful automation platform. It supports modules for different providers and vendors, and in the same time by the PowerShell Desired State Configuration (DSC) framework makes it extremely convenient and easy to be used to provision infrastructures, as a IaC tool.
Cisco Systems, Inc. has developedPowerShell modules, which allow the Cisco UCS Manager, the Cisco Integrated Management Controller (CIMC), and Cisco Intersight to be managed and provisioned and configured with the help of PowerShell.
The Cisco PowerShell modules form the different supported systems are available at the PowerShell Gallery at the following URL:
Note:
The requirement is the local version of Powershell to be minimum 5.1!
The Cisco UCS PowerTool suite is a set of PowerShell modules, which communicate via the UCS XML API. The Cisco UCS is an integrated compute solution, which management is built as XML objects structured in a hierarchical Object Model using an XML schema. More than 98% of that schema is built in the UCS PowerTool laibrary. This allows the PowerShell to be used to communicate, manage and provision the Cisco compute solutions. With the release of Cisco Intersight, as a cloud-based SaaS management platform for the Cisco compute solutions, there is also a Powershell module which supports the Intersight APIs.
The modules in the UCS PowerToll library consists of Microsoft PowerShell Cmdlets, which enable the communication, the retrieval and the change of UCS managed objects. The PowerShell cmdlets are created to work in the following categories:
• Sessions
• Methods
• Queries and Filters
• Configurations and Transactions
To start working with the UCS PowerShell modules, you need to check the version of the PowerShell, as shown in the example (Example 17-10).
Example 17-10 Check PowerShell version
PS /> $PSVersionTable
Name Value
—- —–
PSVersion 7.1.4
PSEdition Core
GitCommitId 7.1.4
OS Linux 4.15.0-29-generic #31-Ubuntu SMP Tue Jul
17 15:39:52 UTC 2018
Platform Unix
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
To install the UCS PowerTool library the packages Cisco.UCS.Core and Cisco.UCSManager need to be installed. The installation is demonstrated in Example 17-11.
Example 17-11 Install Cisco UCS PowerShell Library
PS /> Install-Module ‘Cisco.ucs.core’ -RequiredVersion 2.5.3.0
Untrusted repository
You are installing the modules from an untrusted repository. If you trust this
repository, change its InstallationPolicy value by running the
Set-PSRepository cmdlet. Are you sure you want to install the modules from
‘PSGallery’?
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default
is “N”): A
<… output omitted …>
Do you accept the license terms for module ‘Cisco.UCS.Core’.
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default
is “N”): A
PS />
PS /> Get-Package -Name Cisco.UCS.Core
Name Version Source
ProviderName
—- ——- ——
————
Cisco.UCS.Core 2.5.3.0
https://www.powershellgallery… PowerShellGet
PS /> Install-Module ‘Cisco.UCSManager’ -RequiredVersion 3.0.1.2
Untrusted repository
You are installing the modules from an untrusted repository. If you trust this
repository, change its
InstallationPolicy value by running the Set-PSRepository cmdlet. Are you sure
you want to install the modules from
‘UcsRepository’?
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default
is “N”): A
<… ouput omitted …>
Do you accept the license terms for module ‘Cisco.UCS.Common’.
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default
is “N”): A
PS /> Get-Package -Name Cisco.UCSManager
Name Version Source
ProviderName
—- ——- ——
————
Cisco.UCSManager 3.0.1.2
https://www.powershellgallery… PowerShellGet
After the successful installation of the UCS modules, the next step is to add the modules to the path and import them. After that you can start using the UCS cmdlets. In the examples are shown the installation of the Cisco UCS modules, but the procedure to install the modules for the Cisco IMC is similar.
Once that the UCS PowerShell library modules are installed in PowerShell, then you are ready to start managing Cisco UCS infrastructures. The first step will be to connect to the UCS, as demonstrated in Example 17-12. In that example is demonstrated how to find the needed command, to connect and to verify the status of the connection.
Example 17-12 Check PowerShell version
PS /> Get-Help Connect-Ucs
NAME
Connect-Ucs
SYNOPSIS
Connects to a UCS
SYNTAX
Connect-Ucs [-Name] <string[]> [-Credential] <PSCredential> [-Port
<ushort>] [-NoSsl] [-NotDefault] [-Proxy <WebProxy>] [<CommonParameters>]
Connect-Ucs -LiteralPath <string> -Key <SecureString> [-NotDefault]
[-Proxy <WebProxy>] [<CommonParameters>]
Connect-Ucs -Path <string> -Key <SecureString> [-NotDefault] [-Proxy
<WebProxy>] [<CommonParameters>]
DESCRIPTION
Connects to a UCS. The cmdlet starts a new session using the specified
parameters. One can have more than one connections to a server. PowerTool
Supports working with multiple default servers. This can be enabled by
setting SupportMultipleDefaultUcs using Set-UcsPowerToolConfiguration.
<… output omitted …>
PS /> Connect-Ucs -name 10.10.1.131
cmdlet Connect-Ucs at command pipeline position 1
Supply values for the following parameters:
Credential
User: admin
Password for user admin: ********
NumPendingConfigs : 0
Ucs : UCSPE-10-10-1-131
Cookie :
1628081939/11413e70-ca6a-4557-bb86-e7525d4c1a34
Domains : org-root
LastUpdateTime : 8/25/2021 1:01:27 PM
Name : 10.10.1.131
NoSsl : False
NumWatchers : 0
Port : 443
Priv : {admin, read-only}
PromptOnCompleteTransaction : False
Proxy :
RefreshPeriod : 600
SessionId :
TransactionInProgress : False
Uri : https://10.10.1.131
UserName : admin
Version : 4.1(2c)
VirtualIpv4Address : 10.10.1.131
WatchThreadStatus : None
PS /> Get-UcsPSSession
NumPendingConfigs : 0
Ucs : UCSPE-10-10-1-131
Cookie :
1628081939/11413e70-ca6a-4557-bb86-e7525d4c1a34
Domains : org-root
LastUpdateTime : 8/25/2021 1:01:27 PM
Name : 10.10.1.131
NoSsl : False
NumWatchers : 0
Port : 443
Priv : {admin, read-only}
PromptOnCompleteTransaction : False
Proxy :
RefreshPeriod : 600
SessionId :
TransactionInProgress : False
Uri : https://10.10.1.131
UserName : admin
Version : 4.1(2c)
VirtualIpv4Address : 10.10.1.131
WatchThreadStatus : None
And finally, when the work is done and the connection is no longer needed will be used the command Disconnect-Ucs.
Once the modules of the UCS PowerTool library are installed, then you can query what are the available commands. In the example below (Example 17-13) you will see the command related to working with VLANs are listed.
Example 17-13 List UCS Powershell Cmdlets
PS /> Get-Command -Verb Get | Select-String Vlan
Get-UcsAdaptorVlan
Get-UcsFabricBHVlan
Get-UcsFabricOrgVlanPolicy
Get-UcsFabricPooledVlan
Get-UcsFabricReservedVlan
Get-UcsFabricVlanEp
Get-UcsFabricVlanGroupReq
Get-UcsFabricVlanReq
Get-UcsSwVlan
Get-UcsSwVlanPortNs
Get-UcsSwVlanPortNsOverride
Get-UcsVlan
Get-UcsVlanMemberPort
Get-UcsVlanMemberPortChannel
Get-UcsVmVlan
Get-UcsVnicLifVlan
Get-UcsVnicVlan
Then by using the command Get-UcsVlan can be retrieved information for the existing VLANs on the UCS, as it is use din Example 17-14.
Example 17-14 List UCS Powershell Cmdlets
PS /> Get-UcsVlan
PS /> Get-UcsVlan
AssocPrimaryVlanState : ok
AssocPrimaryVlanSwitchId : NONE
Cloud : ethestclan
CompressionType : included
ConfigIssues :
ConfigOverlap : ok
DefaultNet : no
EpDn :
Global : 0
Id : 1
IfRole : nas-storage
IfType : virtual
Local : 0
Locale : external
McastPolicyName :
Name : default
OperMcastPolicyName : org-root/mc-policy-default
OperState : ok
OverlapStateForA : active
OverlapStateForB : not-active
PeerDn :
PolicyOwner : local
PubNwDn :
PubNwId : 1
PubNwName :
Sacl :
Sharing : none
SwitchId : dual
Transport : ether
Type : lan
Ucs : UCSPE-10-10-1-131
Dn : fabric/eth-estc/net-default
Rn : net-default
Status :
XtraProperty : {}
AssocPrimaryVlanState : ok
AssocPrimaryVlanSwitchId : NONE
Cloud : ethestclan
CompressionType : included
ConfigIssues :
ConfigOverlap : ok
DefaultNet : no
EpDn :
Global : 0
Id : 163
IfRole : nas-storage
IfType : virtual
Local : 0
Locale : external
McastPolicyName :
Name : test_vlan163
OperMcastPolicyName : org-root/mc-policy-default
OperState : ok
OverlapStateForA : active
OverlapStateForB : not-active
From the output in this example, it is visible that there is a VLAN, with the name “test_vlan163”, which exists and is operational on Fabric Interconnect A.
The way that the UCS PowerTool library can be used withy the standalone Cisco UCS C-series servers is by installing also the Cisco.IMC PowerShell modules. You still need to have the Cisco.ucs.core module. The way that the communication happens and how the information is retrieved and manipulated is the same.
Using MS Powershell for the purposes of automating Cisco UCS infrastructure can be convininet and it depends on what are your skills, preferences, and what is the CI/CD solution used.
Leave a Reply