Menu

Virtual Geek

Tales from real IT system administrators world and non-production environment

Part 2: Generate target server node config for PowerShell DSC pull server

Part 1: Build your first Microsoft PowerShell DSC pull server
Part 2: Generate target server node config for PowerShell DSC pull server
Part 3: Configure PowerShell DSC Local configuration manager LCM in pull mode and update configuration
How to force a PowerShell DSC client to refresh configuration from pull server

In my first blog I created http web server for DSC, it is setup and accessible, here I will create a DSC .mof file for a client server, create guid, checksum files and keep it under DSC configuration. Here on the cod lines from 2 to 26, I wrote basic code to create a folder on c:\Tempfolder and environment variable must be present on the system. My remote client server name is 'srv01', I am running this script on DSC server itself. Before make sure you enable winrm psremoting on DSC server and clients using POWERSHELL PS REMOTING BETWEEN STANDALONE WORKGROUP COMPUTERS, It is one of the prerequisite.

microsoft powershell DSC server dsc resource psdesiredstateconfiguration, target node, file, environment dsc resource, desired state configuration, new-guid, copy-ite, new-dscchecksum, mof file generation

Running line 29 and 30 creates a .mof file named srv01.mof under C:\Temp\BasicConf folder. 

In next line 34: New-Guid generates a random guid number, which I need to rename with srv01.mof file name, which achieved with lines from 35 to 37. This mof file is copied under C:\Program Files\WindowsPowerShell\DscServer\Configuration. From this location clients get there configuration through the web server (Same guid I am going to configure on client srv01 in next article). These files are copied in the configuration locatiion as seen in the below screenshot.

Line 38: The New-DSCCheckSum cmdlet generates checksum files for Windows PowerShell Desired State Co nfiguration (DSC) documents and compressed DSC resources. This cmdlet generates a checksum file for each configuration and resource to be used in pull mode. The DSC service uses the checksums to make sure that the correct configuration and resources exist on the target node. Place the checksums together with the associated DSC documents and compressed DSC resources in the DSC service store. It has checksum extension.

microsoft powershell, dsc, desired state configuration windowspowershell dscserver configuration, build pull server with GUID

This was the phase 2 of configuring DSC server, With this I have created a central DSC repository, next is configuring client local configuration manager, which i will write on next article.

Download this script here also this script is available on Github.com.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39

#1: Member server configuration
Configuration BasicConf {
    #Accepts a string value computername or defaults to localhost
    Param (
        [string[]]$ComputerName = 'Localhost'
    )
    Import-DscResource -ModuleName PSDesiredStateConfiguration

    #Target node
    Node $ComputerName {
        #Ensure user is exist
        File TempFolder {
            Ensure             = 'Present'
            DestinationPath    = 'C:\TempFolder'
            Type               = 'Directory' 
        }

        Environment CustomApp {
            Ensure             = 'Present'
            Name               = 'CustomApp'
            Value              = 'C:\TempFolder'
            Path               = $true
            DependsOn          = "[File]TempFolder"
        }
    }
}

#3: Generate .mof file
cd C:\Temp
BasicConf -Computername srv01

#4: Copy .mof files to the DSC configuration location
#$Guid = [guid]::NewGuid()
$Guid = New-Guid | Select-Object -ExpandProperty Guid
$SourceMof = 'C:\Temp\BasicConf\srv01.mof'
$DestinationMof = "C:\Program Files\WindowsPowerShell\DscServer\Configuration\$Guid.mof"
Copy-Item $SourceMof $DestinationMof
New-DscChecksum $DestinationMof

Useful Blogs
PART 1 : POWERSHELL - CREATE LOCAL IIS WEB REPOSITORY FOR DSC MODULE 
PART 2 : POWERSHELL - COPY DSC MODULE REMOTELY USING LOCAL WEB REPOSITORY
POWERSHELL CONVERT EXCEL TO DSC (DESIRED STATE CONFIGURATION) CONFIGURATION HASHTABLE FORMAT
Microsoft Powershell generate random anything (Filename, TempPath, GUID, Password)

Go Back

Comment

Blog Search

Page Views

11272767

Follow me on Blogarama