0

I'm trying to automate some of my processes when adding a new hyper-v vm. One of the steps I have to do manually is add the newly created and attached vhdx to the new virtual machine.

It shows up like this:

Hyper-V Added Drive

Is there a way to automate adding this new vhdx to the vm with a specific drive letter? The name of the vhdx is not the same every time.

I wanted to added that the host server is a hosted dedicated server running Windows 2022 that I have direct access too.

ErocM
  • 226
  • 7
  • 23

1 Answers1

0

DISKPART>select vdisk file="path to your disk"

DiskPart successfully selected the virtual disk file.

DISKPART>attach vdisk

100 perecent completed

Diskpart successfully attached the virtual disk file.

DISKPART> list disk

DISKPART>select disk # <- number of your new disk

DISKPART>assign letter=Z

The key here is you need the ID of the disk you just added which will be the next number from the highest already attached ID Est if you have three disks, you will have 0,1,2 and hen you attach it will be 3.

YOU will have to enumerate the disks before or after to get the ID or if you know the number ahead of time (like there is always one system volume) then assume 1 as 0 will be the first.

Note: If unsure, you can use this as well $(Get-PSDrive -PSProvider FileSystem | ?{$_.CurrentLocation -ne ""}).Length

Sabre
  • 425
  • 2
  • 15