Search This Blog

Friday, 28 July 2017

Create File using DSC PowerShell Script - Part I

PowerShell DSC is one of my favorite topics to teach, because the technology is simply amazing. Usually I do not have enough time with a customer to teach all of the built-in resources. I would guess that the Script resource is one of the least understood.This sample has tested on PSVersion 4.0.

Step 1. Script Resource Log File Example

Here is an elegantly simple use of the Script resource. We could make it more complex in many ways, but I prefer to start out with a simple use case first. The code is its own documentation. Study it carefully.

configuration WinLogAutoGen{
    param()
    #import the module of DSC for using DSCResources.
    Import-DscResource -ModuleName PSDesiredStateConfiguration;
    # use the file resource to create file.
    File windowsupdatelog{
        DestinationPath  = 'C:\Windows\windowsupdate2.log';
        Ensure = 'Present';
        Contents = 'Dev';
    }
 }
#Set mof file path in other word where to generate mof file.
WinLogAutoGen -Outputpath D:\Harshal;
#Run mof file in other word apply mof configuration to server.
Start-DscConfiguration -Wait -Verbose -Force -path D:\Harshal;

Notice the Write-Verbose statements. These are important for logging and output when the resource runs.

Step 2. Output



Reference

Your Turn

Now it is your turn. Take this sample and implement your own script resources. Leave a comment below telling what you accomplished.

Best wishes on your adventure learning DSC!

No comments:

Post a Comment

Elasticsearch - Nodes, clusters, and shards

Elastic Stack Video - Load your gun in short time.   Beginner's Crash Course to Ela...

Recent Post