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.

<#
.SYNOPSIS
	Removes a DRAC user.
.DESCRIPTION
	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.
.PARAMETER Index
	The numerical index of the user to remove.
.EXAMPLE
   Remove-DRACUser -TargetSystem 192.168.100.20 -Index 4
#>

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

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

BEGIN
{
	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 = ""
}
PROCESS
{
	$Error.Clear()
	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"
		return
	}

	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
			return
		}
		elseif($RawLine -match "^cfgUserAdminUserName=(.*)")
		{
			$UserToRemove = $Matches[1]
		}
	}
	if([String]::IsNullOrEmpty($UserToRemove))
	{
		Write-Error "No user found at index $Index"
		return
	}
	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 comment

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