Change CD/DVD Drive Letter using Powershell

Every organization has a standard for the way they configure or assign drive letter to CD/DVD Drive. During Windows OS deployment CD/DVD Drive are assigned the next available drive letter once the OS is applied.
Easy way to change the drive letter would be to run a Powershell Script as part of OS Deployment. Here is the Script, it takes a Mandatory Input – DriveLetter and have tested it on Windows Server 2008 R2 and Windows Server 2012 R2.
# Get Available CD/DVD Drive - Drive Type 5
$DvdDrv = Get-WmiObject -Class Win32_Volume -Filter "DriveType=5"

# Check if CD/DVD Drive is Available
if ($DvdDrv -ne $null)

# Get Current Drive Letter for CD/DVD Drive
$DvdDrvLetter = $DvdDrv | Select-Object -ExpandProperty DriveLetter
Write-Output "Current CD/DVD Drive Letter is $DvdDrvLetter"

# Confirm New Drive Letter is NOT used
if (-not (Test-Path -Path $NewDrvLetter))

# Change CD/DVD Drive Letter
$DvdDrv | Set-WmiInstance -Arguments @{DriveLetter="$NewDrvLetter"}
Write-Output "Updated CD/DVD Drive Letter as $NewDrvLetter"
Write-Output "Error: Drive Letter $NewDrvLetter Already In Use"
Write-Output "Error: No CD/DVD Drive Available !!"


!! Preenesh

This entry was posted in Powershell and tagged , , , . Bookmark the permalink.

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