Eric's Technical Outlet

Learning the hard way so you don't have to

PowerShell: Use RACADM to Delete a Dell DRAC User by Index

Dell’s DRAC web interface allows you to create and modify DRAC users, but not remove them. The RACADM.EXE utility has the power to do this, but the syntax isn’t easy to remember. Rather than look it up each time, you can easily script this with PowerShell.

To use this script, you do need the RACADM.EXE tool installed. Look on Dell’s download page for the server you want to manage, under the Systems Management branch. There should be an entry for DRAC tools.

This script includes the logon credentials hard-coded in plain text. There are plenty of examples on the Internet for storing and retrieving sensitive information like this, so feel free to update the script with something that suits your purposes.

	Removes a DRAC user.
	Removes a DRAC user. Requires Dell's RACADM.EXE utility, which is distributed as part of the Dell DRAC Tools kit.
.PARAMETER TargetSystem
	The IP address or hostname of the target system.
	The numerical index of the user to remove.
   Remove-DRACUser -TargetSystem -Index 4

[CmdletBinding(SupportsShouldProcess=$true, ConfirmImpact="High")]
	[Parameter(Mandatory=$true, HelpMessage="Enter the hostname or IP address of the target")]

	[Parameter(Mandatory=$true, HelpMessage="Enter the index of the user to remove")]
	[ValidateRange(3, 16)]

	New-Variable -Name RACADMExe -Value "C:\Program Files\Dell\SysMgt\rac5\racadm.exe"
	New-Variable -Name RACRootUser -Value "YOUR-DRAC-USER" -Option Constant
	New-Variable -Name RACRootUserPass -Value "YOUR-DRAC-PASSWORD" -Option Constant
	$UserToRemove = ""
	Write-Verbose "Checking for existence of racadm.exe"
	if(!(Test-Path -Path $RACADMExe))
		Write-Error "Run this script from the folder that contains racadm.exe"

	Write-Verbose "Attempting to connect to $TargetSystem"
	[String[]]$RawResult = & $RACADMExe -r $TargetSystem -u $RACRootUser -p $RACRootUserPass getconfig -g cfgUserAdmin -i $Index 2>&1

	foreach($RawLine in $RawResult)
		if($RawLine -cmatch "^ERROR")
			Write-Error $RawLine
		elseif($RawLine -match "^cfgUserAdminUserName=(.*)")
			$UserToRemove = $Matches[1]
		Write-Error "No user found at index $Index"
	if($PSCmdlet.ShouldProcess($UserToRemove, "Remove DRAC user"))
		Write-Verbose "Attempting delete..."
		[String[]]$RawDeleteResult = & racadm -r $TargetSystem -u $RACRootUser -p $RACRootUserPass config -g cfgUserAdmin -o cfgUserAdminUserName -i $Index `"`" 2>&1
		foreach($RawDeleteLine in $RawDeleteResult)
			if($RawDeleteLine -cmatch "^ERROR")
				Write-Error $RawDeleteLine
				return	# only necessary for future-proofing, in case other script is added beyond this
			if($RawDeleteLine -match "successfully")
				Write-Verbose "Deletion of $UserToRemove was successful."
END {}

Leave a Reply

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

You are commenting using your 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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: