Question:
I’m trying to configure a target node via DSC.
I’ve created a .ps1 file with a dummy Configuration; you can see it below; it’s just one of the first examples that you find in DSC sites.
Now I want to compile it into .mof file.
I’ve executed:
1 2 |
PS C:\var\DSC\Configurations> . .\localhost.ps1 |
but it does nothing. The mof file doesn’t appear and no error messages are thrown.
What am I missing?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
Configuration FileResourceDemo { Node "localhost" { File DirectoryCopy { Ensure = "Present" # You can also set Ensure to "Absent" Type = "Directory" # Default is "File". Recurse = $true # Ensure presence of subdirectories, too SourcePath = "C:\Users\Public\Documents\DSCDemo\DemoSource" DestinationPath = "C:\Users\Public\Documents\DSCDemo\DemoDestination" } Log AfterDirectoryCopy { # The message below gets written to the Microsoft-Windows-Desired State Configuration/Analytic log Message = "Finished running the file resource with ID DirectoryCopy" DependsOn = "[File]DirectoryCopy" # This means run "DirectoryCopy" first. } } } |
Answer:
The Configuration
keyword only defines the configuration (think of it like the function
keyword). After that you have to execute it, by calling it like a function (it can even have parameters, though yours does not).
So if, at the end of your .ps1
file you add:
1 2 |
FileResourceDemo |
It will execute it right after defining it.
Or, since you are dot sourcing the file according to your question, you can directly execute it interactively by typing FileResourceDemo
into the prompt. It should even tab-complete.