What if your computers could fix themselves to the right setup without you doing anything?
Why Desired State Configuration (DSC) basics in PowerShell? - Purpose & Use Cases
Start learning this pattern below
Jump into concepts and practice - no test required
Imagine you have 50 computers that all need the same software installed and settings configured. You try to do this by logging into each one and clicking through menus or typing commands manually.
This manual way is slow and tiring. You might forget a step or make a typo on some computers. Fixing mistakes means checking each machine again, which wastes time and causes frustration.
Desired State Configuration (DSC) lets you write a simple script that says how each computer should look. Then DSC makes sure every computer matches that description automatically, fixing any differences without you lifting a finger.
Invoke-Command -ComputerName PC1 { Install-WindowsFeature -Name Web-Server }
Invoke-Command -ComputerName PC2 { Install-WindowsFeature -Name Web-Server }Configuration WebServerConfig {
Node 'PC1','PC2' {
WindowsFeature WebServer {
Name = 'Web-Server'
Ensure = 'Present'
}
}
}
WebServerConfigDSC makes managing many computers easy and reliable by keeping them all in the right state automatically.
A company uses DSC to ensure every new employee's computer has the right software and settings from day one, without IT staff visiting each desk.
Manual setup is slow and error-prone.
DSC scripts describe the desired setup once.
DSC automatically keeps computers consistent and correct.
Practice
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 CQuick Check:
DSC purpose = automatic setup maintenance [OK]
- Thinking DSC only runs scripts once
- Confusing DSC with network monitoring
- Assuming DSC manages user accounts interactively
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 BQuick Check:
DSC block starts with 'Configuration' [OK]
- Using 'Config' instead of 'Configuration'
- Trying to use cmdlets to start config blocks
- Confusing DSC syntax with other PowerShell commands
MyConfig?
Configuration MyConfig {
Node 'localhost' {
File ExampleFile {
DestinationPath = 'C:\temp\example.txt'
Contents = 'Hello DSC'
}
}
}
MyConfigSolution
Step 1: Understand DSC output files
Running a DSC configuration generates a MOF file named after the Node, here 'localhost'.Step 2: Identify the MOF file name
The MOF file will be 'localhost.mof' because the Node is 'localhost'.Final Answer:
localhost.mof -> Option AQuick Check:
DSC MOF file = NodeName.mof [OK]
- Assuming MOF file is named after config
- Confusing MOF with script files
- Expecting output as the destination file
Configuration SampleConfig {
Node 'localhost' {
File MyFile {
DestinationPath = 'C:\temp\file.txt'
Content = 'Test content'
}
}
}
SampleConfig
What is the error in this script?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 DQuick Check:
File resource uses 'Contents' property [OK]
- Using 'Content' instead of 'Contents'
- Thinking Node names must be IP addresses
- Expecting a special end command for configuration
C:\Logs always exists on a remote computer using DSC. Which configuration snippet correctly enforces this desired state?Solution
Step 1: Identify correct resource and properties
To ensure a folder exists, use the File resource with Type='Directory' and Ensure='Present'.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.Final Answer:
Option A snippet correctly ensures folder presence -> Option AQuick Check:
File resource + Type='Directory' + Ensure='Present' = folder exists [OK]
- Using Type='File' for folders
- Omitting Type property for directories
- Using non-existent 'Directory' resource
