Test a DSC Configuration

We will now explain how to compile and apply DSC Configurations.

Getting started

Software Dependencies

Please make sure to have the followings PowerShell Modules installed before proceeding:

  • Baselinemanagement
  • WindowsDefender
  • PowerShellAccessControl

If necessary install them:

  1. Download ‘PowerShellAccessControl’ by following this link: https://gallery.technet.microsoft.com/scriptcenter/PowerShellAccessControl-d3be7b83 and copy the downloaded folder in the following path: ‘C:\Program Files\WindowsPowerShell\Modules’

  2. To install the other modules simply type the commands in the PowerShell

    Install-Module Baselinemanagement
    Install-Module WindowsDefender
    

    possible notifications in PowerShell:

    NuGet provider is required to continue PowerShellGet requires NuGet provider version ‘2.8.5.201’ or newer to interact with NuGet-based repositories. The NuGet provider must be available in ‘C:\Program Files\PackageManagement\ProviderAssemblies’ or ‘C:\Users$env:UserName\AppData\Local\PackageManagement\ProviderAssemblies’. You can also install the NuGet provider by running ‘Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force’. Do you want PowerShellGet to install and import the NuGet provider now? [Y] Yes [N] No [S] Suspend [?] Help (default is “Y”):

    Press “Y” and move on.


    Untrusted repository You are installing the modules from an untrusted repository. If you trust this repository, change its InstallationPolicy value by running the Set-PSRepository cmdlet. Are you sure you want to install the modules from ‘PSGallery’? [Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is “N”):

    Press “A” and move on.

Compile DSC Configuration

Copy the XOAP-Module to C:\Program files\WindowsPowerShell\Modules. Open an elevated PowerShell and change to this root directory.

Ensure DSC Resources are present with:

Get-DscResource -Name XOSS* -Module XOSS*

You can safely generate now a configuration for W2k16 by invoking our default W2k16_1607 script.

.\W2k16_1607.ps1

At the same folderpath of our default script there will be a new directory called “W2k16_1607” afterwards and powershell will prompt:

    Directory: *path of default script*\W2K16_1607


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----        3/29/2020   7:35 PM         564704 localhost.mof

Apply the configuration

Now that you have the compiled MOF, you can apply the configuration to the target node (in this case, the local computer) by calling the Start-DscConfiguration cmdlet.

Start-DscConfiguration -Path "*path of default script*\W2K16_1607" -Force -Wait -Computername localhost