1

I'm trying to create, mount and format VHDX using Powershell in VM. The first step works without any problems:

New-VHD -Path $path -Dynamic -SizeBytes 20GB

But now, when I try to mount it:

Mount-VHD -Path $path

Powershell raises this error:

Mount-VHD : Failed to mount the virtual disk.
The system failed to mount <my_path>.
The operation cannot be performed while the object is in use.
At line:1 char:2
+  Mount-VHD -Path <my_path>
+  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceBusy: (Microsoft.Hyper...l.VMStorageTask:VMStorageTask) [Mount-VHD], Virtualizat
   ionOperationFailedException
    + FullyQualifiedErrorId : ObjectInUse,Microsoft.Vhd.PowerShell.MountVhdCommand

Why does it says that it's in use? What should I do to be able to mount it?

EDIT:

If I try to mount it through context menu, it raises this error:

enter image description here

Milano
  • 18,048
  • 37
  • 153
  • 353

1 Answers1

1

I usually do the same with diskpart (run the below powershell script as administrator):

$diskpartScript= @"
create vdisk file=c:\test.vhd maximum=2000 type=expandable
select vdisk file=c:\test.vhd 
attach vdisk 
create partition primary 
format fs=ntfs label="Test VHD" quick 
assign letter=v
"@

$diskpartScript | diskpart

note: I believe vhd is not getting mounted in your script is because the disk is not initialized and formatted

hope this helps

ClumsyPuffin
  • 3,909
  • 1
  • 17
  • 17