#27986·PowerShell

Hyper-V: Remove-VMDvdDrive followed by Add-VMHardDiskDrive results in error

Author: AngrySvarogCreated Sep 8, 2026Updated Sep 16, 2026
LabelsResolution-ExternalNeeds-Triage

Prerequisites

Steps to reproduce

I have an script to automate setting up a HyperV vm. At some point, I want to removed the installation media (DVD) and replace it with a 2nd VHD.

  1. Stop-VM
  2. If there is a DvdDrive, Remove-VMDvdDrive
  3. Add-VMHardDiskDrive

Results : "Unable to cast object of type 'Microsoft.HyperV.PowerShell.DvdDrive' to type 'Microsoft.HyperV.PowerShell.HardDiskDrive'."

Note: re-running the script succeeds. Speculation: internal state still thinks that the second "drive" is a DvdDrive, but it is actually gone. Re-run starts with new state and so succeeds.

Expected behavior

Able to add Add-VMHardDiskDrive after Remove-VMDvdDrive

Actual behavior

Error: Unable to cast object of type 'Microsoft.HyperV.PowerShell.DvdDrive' to type 'Microsoft.HyperV.PowerShell.HardDiskDrive'.

Error details

Type        : System.Management.Automation.ActionPreferenceStopException
ErrorRecord :
    Exception             :
        Type    : Microsoft.PowerShell.Commands.WriteErrorException
        Message : Unable to cast object of type 'Microsoft.HyperV.PowerShell.DvdDrive' to type 'Microsoft.HyperV.PowerShell.HardDiskDrive'.

Environment data

Name                           Value
----                           -----
PSVersion                      7.6.5
PSEdition                      Core
GitCommitId                    7.6.5
OS                             Microsoft Windows 10.0.26200
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.4
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

No response