powershellwmidrive-letter

Assign drive letter to CD-Drive using PowerShell


I have a CD drive, without a drive letter, because I am trying to automatically rearrange Volumes. I want to use PowerShell a drive letter to the CD drive (here ISOIMAGE).

Picture of disk management

I removed it using the following:

$cdDrive = Get-WmiObject -Class Win32_volume -Filter 'DriveType=5' | Select-Object -First 1
$cdDrive | Set-WmiInstance -Arguments @{ DriveLetter = $null }

I assumed that something like this would therefore work:

$cdDrive | Set-WmiInstance -Arguments @{ DriveLetter = "F:\" }

To my confusion, PowerShell responded like this:

Set-WmiInstance : The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that take pipeline input.

I also tried:

Get-Volume | ? DriveType -eq "cd-rom" | Set-WmiInstance -Arguments @{ DriveLetter = "F:\" };
Get-Volume | ? DriveType -eq "cd-rom" | Set-WmiInstance -Arguments @{ DriveLetter = "F:\"; Label="bruh" };
Get-Volume | ? DriveType -eq "cd-rom" | Set-Partition -NewDriveLetter "F";

Solution

  • It turns out $cdDrive has a method called AddMoundPoint, so $cdDrive.AddMountPoint("F:") worked.