0
0
PowerShellscripting~30 mins

Desired State Configuration (DSC) basics in PowerShell - Mini Project: Build & Apply

Choose your learning style9 modes available
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
Need a 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
Need a 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
Need a 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
Need a hint?

Use Get-DscConfigurationStatus to get the status object. Then use Format-List to print it nicely.