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
Desired State Configuration (DSC) Basics
📖 Scenario: You are a system administrator who wants to ensure a server always has a specific folder with the right permissions. You will use Desired State Configuration (DSC) in PowerShell to define and enforce this setup automatically.
🎯 Goal: Build a simple DSC configuration script that creates a folder at a specified path and sets its permissions. You will define the configuration, set parameters, apply the configuration, and check the result.
📋 What You'll Learn
Create a DSC configuration named FolderSetup
Use the File resource to create a folder at C:\DSCTestFolder
Set the folder to be present with Ensure = 'Present'
Add a configuration data variable $FolderPath with the folder path
Apply the configuration using Start-DscConfiguration
Output the status of the DSC application
💡 Why This Matters
🌍 Real World
DSC helps system administrators automatically keep servers in a desired state, reducing manual errors and saving time.
💼 Career
Understanding DSC is valuable for roles in system administration, DevOps, and cloud infrastructure management.
Progress0 / 4 steps
1
Create the DSC Configuration
Write a DSC configuration named FolderSetup that uses the File resource to create a folder at C:\DSCTestFolder. Set Ensure = 'Present' and Type = 'Directory' inside the resource block.
PowerShell
Hint
Use the configuration keyword to start. Inside, use File resource with the exact name TestFolder. Set DestinationPath to 'C:\DSCTestFolder'.
2
Add a Configuration Data Variable
Create a variable called $FolderPath and set it to the string 'C:\\DSCTestFolder'. Then update the DestinationPath in the File resource inside FolderSetup to use this variable.
PowerShell
Hint
Define $FolderPath after the configuration block. Replace the hardcoded path in DestinationPath with $FolderPath.
3
Apply the DSC Configuration
Call the FolderSetup configuration to generate the MOF file by running FolderSetup. Then apply the configuration using Start-DscConfiguration with the path ./FolderSetup and the -Wait and -Verbose flags.
PowerShell
Hint
Run the configuration name as a command to create the MOF file. Then use Start-DscConfiguration with the folder path where the MOF file is generated.
4
Output the DSC Application Status
After applying the configuration, run Get-DscConfigurationStatus and print its output to show the status of the DSC application.
PowerShell
Hint
Use Get-DscConfigurationStatus to get the status object. Then use Format-List to print it nicely.
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
Step 1: Understand DSC's role
DSC is designed to keep system configurations consistent automatically.
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.
Final Answer:
To automatically keep your computer setup as you want it -> Option C
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
Step 1: Recall DSC syntax
The DSC configuration block always starts with the keyword 'Configuration' followed by the name.
Step 2: Check options
Only Configuration MyConfig { } uses the correct keyword 'Configuration' to define the block.
Final Answer:
Configuration MyConfig { } -> Option B
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?
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
Step 1: Check File resource properties
The File resource requires the property 'Contents' (plural), not 'Content'.
Step 2: Validate other parts
Node 'localhost' is valid, DestinationPath can be a file path, and no 'End-Configuration' command exists.
Final Answer:
The property 'Content' should be 'Contents' in the File resource -> Option D
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?