Continuing exploration of uses of the PowerShell 4.0 feature, Desired State Configuration (DSC), let’s explore how to use DSC to monitor files and folders.
In this example, I want check to see if my backup and recovery software is installed on my Hyper-V hosts. DSC includes a resource called Package which facilitates monitoring and installing or uninstalling software packages on your servers. The Package resource contains the following elements:

Package [string] #ResourceName
Name = [string]
Path = [string]
ProductId = [string]
[ Arguments = [string] ]
[ Credential = [PSCredential] ]
[ Ensure = [string] { Absent | Present } ]
[ LogPath = [string] ]
[ DependsOn = [string[]] ]
[ ReturnCode = [UInt32[]] ]

I’ll create a DSC PowerShell script for testing for the presence of my backup agent using the Package resource. You should have your software package MSI or Setup.exe file downloaded to the server you are using to manage your DSC resources. You can enumerate multiple servers inside your Configuration .ps1 script to check the configuration of each server. You can run the Enable-PSRemoting cmdlet on each target server or node in your environment to allow the DSC functions to be run remotely from your managing server. The contents of my script are as follows:

This PowerShell script defines the configuration block and also invokes the UnitrendsAgent configuration – note line 18. This will cause the script to execute the configuration. It checks for the presence of the Unitrends Agent package, and installs it from the Path location in the case that it isn’t installed. You can inversely uninstall a package by changing the Ensure value from Present to Absent.

There is a great Free eBook in the Microsoft cloud OneDrive on Desired State Configuration which explains in detail how to plan and use DSC: The DSC Book

About Unitrends

Unitrends increases uptime, productivity and confidence in a world in which IT professionals must do more with less. Unitrends leverages high-availability hardware and software engineering, cloud economics, enterprise power with consumer-grade design, and customer-obsessed support to natively provide all-in-one enterprise backup and continuity. The result is a “one throat to choke” set of offerings that allow customers to focus on their business rather than backup.