How to attach VHD(X) files as data disks to Hyper-V VM with DSC

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of Gerhard Glenk Gerhard Glenk 5 months ago.

  • Author
    Posts
  • #45700
    Profile photo of Gerhard Glenk
    Gerhard Glenk
    Participant

    Hello,

    I'm looking for a way to attach VHD(x) files as data disks to Hyper-V VMs with DSC. I have a DSC configuration to create the VM with the xVMHyperv resource and to create the VHD(x) files with the xVHD resource. But now how can I attach such a virtual hard disk file let's say to port 2 of SCSI controller 1 as a data disk within the DSC configuration?

    I know there are cmdlets like Add-VMHardDiskDrive for this purpose. But how to do that in a DSC configuration? Are there any resource implementations out there? Or have I to write my own DSC resource for that?

    Thank you for any hint,
    Gerhard

  • #45730
    Profile photo of Monte Hazboun
    Monte Hazboun
    Participant

    Hi Gerhard,

    I ended up having to create my own resource to do this as the xHyper-V DSC resources only seems to support having one drive attached to a VM on creation.

    You can find the resource here: https://github.com/Monte-Hazboun/cVHDtoVMConnector

    You can call it in your configuration like so:

    cVHDtoVMConnector ServerEDrive {
    VMName = "Server"
    VHDPath = [Path to VHD]
    ControllerType = "SCSI"
    ControllerNumber = 0
    ControllerLocation = 1
    Ensure = "Present"
    DependsOn = "[xVHD]VHDcreationresource"
    }

  • #45873
    Profile photo of Gerhard Glenk
    Gerhard Glenk
    Participant

    Hi Monte,

    thank you very much for your quick answer. That's exactly what I was looking for. I tried your resource and it did its job. Great!
    Once more thank you for your help.

    Gerhard

You must be logged in to reply to this topic.