UCSBaseScript

The script below is a basic example to collect information from Cisco UCS PODS, this script is a base script which I use to collate all the Cisco UCS Information, This information is then injected in MS SQL servers to produce capacity and Audit reports.Get-

The first part of the script will set the execution policy and import the Cisco UCS Powershell Module.

Set-ExecutionPolicy RemoteSigned -Confirm:$false
Import-Module “C:\Program Files (x86)\Cisco\Cisco UCS PowerTool\Modules\CiscoUcsPS\CiscoUcsPS.psd1”

Then we will define the management IP addresses for the Cisco UCS POD’s.

Set-PowerCLIConfiguration -DefaultVIServerMode Multiple -Scope User -Confirm:$false

In the next part of the script we define the script Variables and set the Powershell commands into the variables, in the below we are extracting the information in a specific order, this is to enable an import into a MS SQL Database to help plan capacity.

#Datacenter1
$DCAUCSP0D01 = “10.10.1.6”
$DCAUCSP0D02 = “10.20.1.6”
#Datacenter2
$DCBUCSP0D01 = “10.30.1.6”
$DCBUCSP0D02 = “10.40.1.6”

The Next step in the base script is to define which Cisco UCS Pods we are going run the script against, lets set a variable and place the UCS POD’s into the variable.

$UCSPODS = @( $DCAUCSP0D01, $DCAUCSP0D02, $DCBUCSP0D01, $DCBUCSP0D02)

Then we will create the credentials to connect to the UCS POD’s, I use a read only account to obtain information.

$podUserName = “UCS_AUDIT_RO”
$podPassword = “!!StrongPassword1!
$podPassword = ConvertTo-SecureString -String $podPassword -AsPlainText -Force
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $podUserName, $podPassword

The next step is to create the output folder for the scripts to place the information obtained.

#Define the Output Directory
$dirRoot = “Somewhere local to your laptop, server\”

Next we create the CMDLET’s to execute the one line commands

These CMDLET’s can vary depending what information is required, I extract all the information possible from all the Cisco UCS Pods, details in the UCS Table here

Then we create the Foreach Loop for the commands to run, these commands are contained in the Cisco UCS table here, add in the required information.

foreach ($UCSPOD in $UCSPODS) {
#connect to the UCS system
$ucsConnection = Connect-Ucs $UCSPOD -Credential $cred

Finally we disconnect from each UCS pod in the Foreach Loop

#disconnect from the system
disconnect-ucs

The full base script looks like the following example

 

#Set The execution Policy
Set-ExecutionPolicy RemoteSigned -Confirm:$false
# Import the Cisco UCS Powertool Module
Import-Module “C:\Program Files (x86)\Cisco\Cisco UCS PowerTool\Modules\CiscoUcsPS\CiscoUcsPS.psd1”
#Define the Cisco UCS Management PODs and their IP Addresses or FQDN
#Datacenter1
$DCAUCSP0D01 = “10.10.1.6”
$DCAUCSP0D02 = “10.20.1.6”
#Datacenter2
$DCBUCSP0D01 = “10.30.1.6”
$DCBUCSP0D02 = “10.40.1.6”
# Define UCS PODs to execute script against
$UCSPODS = @( $DCAUCSP0D01, $DCAUCSP0D02, $DCBUCSP0D01, $DCBUCSP0D02)
# Create the Cisco UCS Credentials
$podUserName = “UCS_AUDIT_RO”
$podPassword = “!!StrongPassword1!
$podPassword = ConvertTo-SecureString -String $podPassword -AsPlainText -Force
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $podUserName, $podPassword
#Define the Output Directory

$dirRoot = “Somewhere local to your laptop, server\”
# Define the powershell CMDLETS

#—————————————————————-
Cisco UCS Oneliners can be found here below is an example for the Fabric Interconnect information
$getucsNetworkelement = “get-ucsNetworkelement | select AdminInBandIfState,ID,InBandIfGW,InBandMask,InBandIfVnet,InventoryStatus,OobIfIP,Model,OobIfGW,OobIfMask,Operability,Revision,Serial,Thermal,TotalMemory,Dn,Rn,Status,UCS”
#—————————————————————-
# Create the Foreach Loop for the commands to run
foreach ($UCSPOD in $UCSPODS) {
#connect to the UCS system
$ucsConnection = Connect-Ucs $UCSPOD -Credential $cred
#—————————————————————-
#GET_FABRIC_INTERCONNECT INFORMATION
#create the file path for exporting FI data.
$getUCSFIFilePath = $dirRoot + “get-FI_” + $ucsconnection.ucs + “.csv”
#get UCS fabric Interconnect info.
invoke-expression $getUCSNetworkElement | export-csv $getUCSFIFilePath -delimiter ^ -notype
#Take out the quotation marks in the CSV files.
(get-content $getUCSFIFilePath ) | % {$_ -replace ‘”‘, “”} | out-file $getUCSFIFilePath -Fo -En ascii
#—————————————————————-
#disconnect from the system
disconnect-ucs
}