Introduction
Desired State Configuration (DSC) helps you keep your computer or server set up the way you want it, automatically fixing things if they change.
Jump into concepts and practice - no test required
Configuration ConfigName {
Node 'localhost' {
ResourceName ResourceType {
Property1 = 'Value1'
Property2 = 'Value2'
}
}
}
ConfigName
Start-DscConfiguration -Path ./ConfigName -Wait -VerboseConfiguration SampleConfig {
Node 'localhost' {
File ExampleFolder {
DestinationPath = 'C:\Example'
Type = 'Directory'
Ensure = 'Present'
}
}
}
SampleConfig
Start-DscConfiguration -Path ./SampleConfig -Wait -VerboseConfiguration InstallNotepadPlusPlus {
Node 'localhost' {
Package NotepadPlusPlus {
Name = 'Notepad++'
Path = 'C:\Installers\npp.8.5.2.Installer.exe'
ProductId = ''
Ensure = 'Present'
}
}
}
InstallNotepadPlusPlus
Start-DscConfiguration -Path ./InstallNotepadPlusPlus -Wait -VerboseConfiguration EnsureFolder {
Node 'localhost' {
File MyFolder {
DestinationPath = 'C:\MyFolder'
Type = 'Directory'
Ensure = 'Present'
}
}
}
EnsureFolder
Start-DscConfiguration -Path ./EnsureFolder -Wait -VerboseMyConfig?
Configuration MyConfig {
Node 'localhost' {
File ExampleFile {
DestinationPath = 'C:\temp\example.txt'
Contents = 'Hello DSC'
}
}
}
MyConfigConfiguration SampleConfig {
Node 'localhost' {
File MyFile {
DestinationPath = 'C:\temp\file.txt'
Content = 'Test content'
}
}
}
SampleConfig
What is the error in this script?C:\Logs always exists on a remote computer using DSC. Which configuration snippet correctly enforces this desired state?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.