Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm having some trouble understanding the DSC script resource, in particular the test and get phases. I am trying to change the default Hyper-V VHD and VM paths, but can't seem to work out how to validate those via DSC scripts.

I usually use the below command to accomplish this goal:

Set-VMHost -ComputerName NAME -VirtualHardDiskPath D:\HV\VHD -VirtualMachinePath D:\HV\VM

Thanks!

share|improve this question

1 Answer 1

up vote 2 down vote accepted

The DSC Script Resource needs three blocks:

SetScript
- This is run to apply the desired configuration
TestScript
- This is run to see whether the desired configuration should be reapplied
GetScript
- This script should return a hashtable with information about the current configuration

In your situation that would translate to something like:

Script SetHypVPaths {
    SetScript = { 
        Set-VMHost -VirtualHardDiskPath D:\HV\VHD -VirtualMachinePath D:\HV\VM 
    }
    TestScript = {
        $VMHost = Get-VMHost
        return ($VMHost.VirtualHardDiskPath -eq "D:\HV\VHD" -and $VMHost.VirtualMachinePath -eq "D:\HV\VM")
    }
    GetScript = {
        $VMHost = Get-VMHost
        return @{
            VirtualHardDiskPath = $VMHost.VirtualHardDiskPath
            VirtualMachinePath = $VMHost.VirtualMachinePath
        }
    }
}
share|improve this answer
    
That is exactly what I needed thank you! –  Garrett Dumas Jul 31 at 20:22

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.