Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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


share|improve this question
up vote 2 down vote accepted

The DSC Script Resource needs three blocks:

- This is run to apply the desired configuration
- This is run to see whether the desired configuration should be reapplied
- 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 '14 at 20:22

Your Answer


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.