Bird
Raised Fist0
PowerShellscripting~20 mins

Desired State Configuration (DSC) basics in PowerShell - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
DSC Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the output of this DSC configuration block?
Given the following DSC configuration, what will be the output when you run Start-DscConfiguration -Path .\MyConfig -Wait -Verbose?
PowerShell
Configuration MyConfig {
    Node localhost {
        File ExampleFile {
            DestinationPath = "C:\\Temp\\example.txt"
            Contents = "Hello DSC"
            Ensure = "Present"
        }
    }
}

MyConfig
Start-DscConfiguration -Path .\MyConfig -Wait -Verbose
AThe file is created but empty because Contents is ignored.
BAn error occurs because the DestinationPath is invalid.
CThe file C:\Temp\example.txt is created with content 'Hello DSC'.
DNothing happens because the configuration is not applied.
Attempts:
2 left
💡 Hint
Think about what the File resource does in DSC and what the Ensure property means.
📝 Syntax
intermediate
2:00remaining
Identify the syntax error in this DSC configuration snippet
Which option correctly fixes the syntax error in this DSC configuration snippet?
PowerShell
Configuration SampleConfig {
    Node localhost {
        File SampleFile {
            DestinationPath = "C:\\Temp\\sample.txt"
            Contents "Sample content"
            Ensure = "Present"
        }
    }
}
AAdd an equals sign after Contents: Contents = "Sample content"
BRemove the quotes around Sample content: Contents = Sample content
CAdd a comma after Contents: Contents = "Sample content",
DChange DestinationPath to Destination = "C:\\Temp\\sample.txt"
Attempts:
2 left
💡 Hint
Look carefully at the property assignments inside the resource block.
🔧 Debug
advanced
2:00remaining
Why does this DSC configuration fail to apply?
This DSC configuration is supposed to create a directory, but it fails. What is the reason?
PowerShell
Configuration CreateFolder {
    Node localhost {
        File NewFolder {
            DestinationPath = "C:\\NewFolder"
            Type = "Directory"
            Ensure = "Present"
        }
    }
}

CreateFolder
Start-DscConfiguration -Path .\CreateFolder -Wait -Verbose
AThe Node name 'localhost' is invalid and should be replaced with the actual computer name.
BThe DestinationPath is missing a trailing backslash.
CThe Ensure property must be set to 'Created' instead of 'Present'.
DThe 'Type' property is invalid; it should be 'Type = 'Directory'' is correct, but the File resource does not support 'Type'.
Attempts:
2 left
💡 Hint
Check the documentation for the File resource properties.
🚀 Application
advanced
2:00remaining
How to ensure a Windows feature is installed using DSC?
You want to use DSC to make sure the 'Web-Server' Windows feature is installed on a server. Which configuration snippet will achieve this?
A
Configuration WebServer {
    Node localhost {
        WindowsFeature IIS {
            Name = "Web-Server"
            Ensure = "Present"
        }
    }
}
B
Configuration WebServer {
    Node localhost {
        WindowsFeature IIS {
            FeatureName = "Web-Server"
            State = "Installed"
        }
    }
}
C
Configuration WebServer {
    Node localhost {
        WindowsFeature IIS {
            Name = "Web-Server"
            State = "Present"
        }
    }
}
D
Configuration WebServer {
    Node localhost {
        WindowsFeature IIS {
            FeatureName = "Web-Server"
            Ensure = "Installed"
        }
    }
}
Attempts:
2 left
💡 Hint
Check the correct property names and values for the WindowsFeature resource.
🧠 Conceptual
expert
2:00remaining
What happens if you run Start-DscConfiguration twice with the same configuration?
You have applied a DSC configuration named 'MyConfig' on a node. You run Start-DscConfiguration -Path .\MyConfig -Wait -Verbose again immediately. What will happen?
ADSC will uninstall all resources and then apply the configuration again.
BDSC will reapply the configuration and recreate all resources regardless of current state.
CDSC will throw an error because the configuration is already applied.
DDSC will detect the node is already in the desired state and make no changes.
Attempts:
2 left
💡 Hint
Think about the purpose of DSC's idempotency.

Practice

(1/5)
1. What is the main purpose of Desired State Configuration (DSC) in PowerShell?
easy
A. To monitor network traffic continuously
B. To write scripts that run only once manually
C. To automatically keep your computer setup as you want it
D. To create user accounts interactively

Solution

  1. Step 1: Understand DSC's role

    DSC is designed to keep system configurations consistent automatically.
  2. Step 2: Compare options

    Only To automatically keep your computer setup as you want it describes automatic maintenance of computer setup, which is DSC's goal.
  3. Final Answer:

    To automatically keep your computer setup as you want it -> Option C
  4. Quick Check:

    DSC purpose = automatic setup maintenance [OK]
Hint: DSC means automatic setup enforcement [OK]
Common Mistakes:
  • Thinking DSC only runs scripts once
  • Confusing DSC with network monitoring
  • Assuming DSC manages user accounts interactively
2. Which of the following is the correct way to start a DSC configuration block in PowerShell?
easy
A. Start-DSCConfig MyConfig { }
B. Configuration MyConfig { }
C. Config MyConfig { }
D. New-DSCConfig -Name MyConfig { }

Solution

  1. Step 1: Recall DSC syntax

    The DSC configuration block always starts with the keyword 'Configuration' followed by the name.
  2. Step 2: Check options

    Only Configuration MyConfig { } uses the correct keyword 'Configuration' to define the block.
  3. Final Answer:

    Configuration MyConfig { } -> Option B
  4. Quick Check:

    DSC block starts with 'Configuration' [OK]
Hint: DSC configs start with 'Configuration' keyword [OK]
Common Mistakes:
  • Using 'Config' instead of 'Configuration'
  • Trying to use cmdlets to start config blocks
  • Confusing DSC syntax with other PowerShell commands
3. Given this DSC configuration snippet, what will be the output file name generated after running MyConfig?
Configuration MyConfig {
  Node 'localhost' {
    File ExampleFile {
      DestinationPath = 'C:\temp\example.txt'
      Contents = 'Hello DSC'
    }
  }
}
MyConfig
medium
A. localhost.mof
B. MyConfig.ps1
C. example.txt
D. MyConfig.mof

Solution

  1. Step 1: Understand DSC output files

    Running a DSC configuration generates a MOF file named after the Node, here 'localhost'.
  2. Step 2: Identify the MOF file name

    The MOF file will be 'localhost.mof' because the Node is 'localhost'.
  3. Final Answer:

    localhost.mof -> Option A
  4. Quick Check:

    DSC MOF file = NodeName.mof [OK]
Hint: DSC MOF file named after Node, not config [OK]
Common Mistakes:
  • Assuming MOF file is named after config
  • Confusing MOF with script files
  • Expecting output as the destination file
4. You wrote this DSC configuration but get an error when running it:
Configuration SampleConfig {
  Node 'localhost' {
    File MyFile {
      DestinationPath = 'C:\temp\file.txt'
      Content = 'Test content'
    }
  }
}
SampleConfig
What is the error in this script?
medium
A. The Node name 'localhost' is invalid
B. The configuration block must end with 'End-Configuration' command
C. The DestinationPath must be a folder, not a file
D. The property 'Content' should be 'Contents' in the File resource

Solution

  1. Step 1: Check File resource properties

    The File resource requires the property 'Contents' (plural), not 'Content'.
  2. Step 2: Validate other parts

    Node 'localhost' is valid, DestinationPath can be a file path, and no 'End-Configuration' command exists.
  3. Final Answer:

    The property 'Content' should be 'Contents' in the File resource -> Option D
  4. Quick Check:

    File resource uses 'Contents' property [OK]
Hint: File resource property is 'Contents' plural [OK]
Common Mistakes:
  • Using 'Content' instead of 'Contents'
  • Thinking Node names must be IP addresses
  • Expecting a special end command for configuration
5. You want to ensure a folder C:\Logs always exists on a remote computer using DSC. Which configuration snippet correctly enforces this desired state?
hard
A.
Configuration EnsureFolder {
  Node 'RemotePC' {
    File LogsFolder {
      DestinationPath = 'C:\Logs'
      Type = 'Directory'
      Ensure = 'Present'
    }
  }
}
B.
Configuration EnsureFolder {
  Node 'RemotePC' {
    Directory LogsFolder {
      Path = 'C:\Logs'
      State = 'Exists'
    }
  }
}
C.
Configuration EnsureFolder {
  Node 'RemotePC' {
    File LogsFolder {
      DestinationPath = 'C:\Logs'
      Ensure = 'Present'
    }
  }
}
D.
Configuration EnsureFolder {
  Node 'RemotePC' {
    File LogsFolder {
      DestinationPath = 'C:\Logs'
      Type = 'File'
      Ensure = 'Present'
    }
  }
}

Solution

  1. Step 1: Identify correct resource and properties

    To ensure a folder exists, use the File resource with Type='Directory' and Ensure='Present'.
  2. Step 2: Check options for correctness

    Configuration EnsureFolder {
      Node 'RemotePC' {
        File LogsFolder {
          DestinationPath = 'C:\Logs'
          Type = 'Directory'
          Ensure = 'Present'
        }
      }
    }
    correctly uses File resource with Type='Directory' and Ensure='Present'.
    Configuration EnsureFolder {
      Node 'RemotePC' {
        File LogsFolder {
          DestinationPath = 'C:\Logs'
          Ensure = 'Present'
        }
      }
    }
    misses Type, D wrongly uses Type='File', B uses a non-existent Directory resource.
  3. Final Answer:

    Option A snippet correctly ensures folder presence -> Option A
  4. Quick Check:

    File resource + Type='Directory' + Ensure='Present' = folder exists [OK]
Hint: Use File resource with Type='Directory' to create folders [OK]
Common Mistakes:
  • Using Type='File' for folders
  • Omitting Type property for directories
  • Using non-existent 'Directory' resource