DevOps: PS/DSC Multiple Servers, Different Configs
Author: jason
Date: 2015-09-01 13:43:31
Category: Technical

In the previous article I showed a small PowerShell Desired State Configuration script that "ensured" the folder c:temp was present on the server. Now I'm going to show how you can set a TempDir variable for each server node, so the temp directory can be different on each server.


Code


# This is where we specify the servers we want to execute against
$ConfigurationData = @{
AllNodes = @(
@{ NodeName = "ServerA"
TempDir = "c:\temp";}
@{ NodeName = "ServerB";
TempDir = "c:\temp";}
@{ NodeName = "ServerC";
TempDir = "d:\temp";}
);
} # end config data

# This sets up the "state" we want those above servers to be in
Configuration QuickTest {

# Start configuration actions
Node $AllNodes.NodeName {

File MakeTemp {
Ensure = "Present"
Type = "Directory"
DestinationPath = $Node.TempDir
} # end state

} # end node

} # end config

# This makes the MOF file(s)
QuickTest -ConfigurationData $ConfigurationData –Verbose

# This runs the MOF file
Start-DSCConfiguration -Wait -Force -Verbose -Path .\QuickTest







jason @ jasonthomasfrance.com - www.masterstationlog.com - copyright 2009