Assume that you're running the Remove-VMHardDiskDrive Windows PowerShell command on a virtual machine. If you run an Add-VMHardDiskDrive command during a repetitive call (a consistent loop) before Remove-VMHardDiskDrive has finished removing the current disk, the two commands enter a race condition, and you receive the following error message:
Add-VMHardDiskDrive : 'VMName' failed to add resources. (Virtual machine ID GUID)
Cannot add 'Host diskpath = Msvm_DiskDrive.CreationClassName="Msvm_Di
skDrive",DeviceID="DeviceID",SystemCreationClassNa
me="Msvm_ComputerSystem",SystemName="Host name"'. The physical disk is already connected to the virtual machine 'VMName'. (Virtual machine ID
GUID)
A parameter that is not valid was passed to the operation.
At line:1 char:1
+ Add-VMHardDiskDrive -VMName ' ' -DiskNumber X
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (Microsoft.HyperV.PowerShell.VMTask:VMTask)
[Add-VMHardDiskDrive], VirtualizationOperationFailedException
+ FullyQualifiedErrorId : InvalidParameter,Microsoft.HyperV.PowerShell.Commands.AddVMHardDiskDriveCommand