vTesseract









My name is Josh Atwell and I've been working in the IT industry exclusively since 2004. I've received my VCAP-DCD, VCAP-DCA, VCP3,4 certifications. I am currently working as a VMware administrator for Cisco.

vTesseract is my personal presence for my thoughts, musings, and technical write-ups involving PowerShell, datacenter virtualization and other technologies I come across daily. The opinions and thoughts on this site are my own and are not endorsed or affiliated by my employer or anyone else. This is done on my own free time and all work is limited based on my time and available resources. Your comments, thoughts, opinions are welcome. Thanks for reading!

Current Resume-CV

Mon Feb 6

UCS - Remove Role #PowerShell Script

I have been reading up and browsing the Cisco UCS PowerTool to learn about all the many cool new cmdlets available.  I recently upgraded to version 0.9.6.0 which has over 1400 cmdlets!  Whoa!  That’s just a few more than the 149 that were released last year.  Make sure you read my earlier post talking about the beta version 0.9.6.0 release.

Clearly I have only scratched the surface in my “tinkering” but last week I got my first real request for making changes in our substantially large UCS environment.  As always I will eliminate any specifics and go to the root.  We had a role on a large number of UCS systems that we didn’t need/want any longer.  Manually this would take forever so to PowerShell we go!  The UCSPowerTool makes this super easy!

The following script allows you to import a list of all of your UCSMs and remove a specified role.  I have set a Test-Role and a temp location for the import file.  You will want to replace these values for your own usage.  I have included screenshots at the end of this post!  Enjoy and may the -force be with you!

<#
====================================================================
Author(s):	Josh Atwell 
 				
File: 		UCS-Remove-Role.ps1
Purpose: 	Removes user specified role from each UCSM listed.
 
Date:		2012-01-31
Notes:		1. This script requires the UCSPowerTool 0.9.6.0
		2. Provide list of UCSMs to connect to.  
		3. Specify Role you wish to have removed from each.
References:	http://developer.cisco.com/web/unifiedcomputing/microsoft 
====================================================================
Disclaimer: This script is written as best effort and provides no 
warranty expressed or implied. Please contact the author(s) if you 
have questions about this script before running or modifying
====================================================================
#>
#	Begin User Input
$file = "C:\Temp\ucspe.txt"
$role = "Test-Role"
#	End User Input

#	Load CiscoUcsPS Module if Needed
If ((Get-Module "CiscoUcsPS" -ErrorAction SilentlyContinue) -eq $null) {
Import-Module "C:\Program Files (x86)\Cisco\Cisco UCS PowerTool\CiscoUcsPS.psd1"
}

#	Capture credentials to be used for all UCSM Connections.
$cred = Get-Credential

Foreach($ucs in Get-Content $file){
Connect-UCS $ucs -Credential $cred
Write-Host "Removing role $role on $ucs"
Get-UcsRole $role | Remove-UcsRole -Force 
Disconnect-UCS
}
#	End Script


You can see the Test-Role

From UCS PowerTool

The script will prompt for your credentials.  In a later post I will demonstrate how you can make this easier.  You can also get that information from the Users Guide available for download with the 0.9.6.0 zip file.

And that’s all there is to it!  The script even disconnects that session.  Again, there are easier ways for managing your connections and credentials but that will be for a later post.

And there you have it.  Your Test-Role has been removed!

blog comments powered by Disqus