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  Gerhard Glenk 1 year, 10 months ago.

  • Author
  • #45700

    Gerhard Glenk


    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,

  • #45730

    Monte Hazboun

    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:

    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"

    • This reply was modified 1 year, 10 months ago by  Monte Hazboun.
  • #45873

    Gerhard Glenk

    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.


You must be logged in to reply to this topic.