Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Gael gaelcolas

🏠
Working from home
View GitHub Profile
@gaelcolas
gaelcolas / Invoke-TestHandlerAction.ps1
Created Nov 7, 2018
Example of a Datum handler that can reference another datum based on its path (rough and dirty)
View Invoke-TestHandlerAction.ps1
function Invoke-TestHandlerAction {
Param(
$Password,
$test,
$Datum,
$Node,
View MyDscConfig.ps1
Configuration MyDscConfig {
# Import the module that has the 'ServerType' configuration
Import-DscResource -ModuleName Platform
# Import the module that has the 'Application' Configuration
Import-DscResource -ModuleName Product
$ConfigurationData.AllNodes.Nodename {
$ConfigurationData.Roles.($Node.Role).configurations.Foreach{
$ConfigurationName = $_
$ConfigurationParameters = $ConfigurationData.Roles.($Node.Role).($ConfigurationName)
View Get-DscSplattedResource.ps1
function Global:Get-DscSplattedResource {
[CmdletBinding()]
Param(
[String]
$ResourceName,
[String]
$ExecutionName,
[hashtable]
View pseudoCodeDscConfig.ps1
foreach($Node in $ConfigurationData.AllNodes) {
# Retrieving the DSC Composite Resource name to include
$configurations = $ConfigurationData.Roles.($Node.Role).configurations
foreach($ConfigurationName in $configurations) {
$ConfigurationParameters = $ConfigurationData.Roles.($Node.Role).($ConfigurationName)
# Splat the Configuration Parameters defined in the Role to the Composite resource
&$ConfigurationName @ConfigurationParameters
}
}
View ConfigData.ps1
$ConfigurationData = @{
AllNodes = @(
@{
Nodename = 'SRV01'
Role = 'ServerType1_Application'
},
@{
Nodename = 'SRV02'
Role = 'ServerType2_Application'
}
View MyDscConfig.ps1
Configuration MyDSCConfig {
Node $ConfigurationData.AllNodes.nodename {
if($Node.roles -contains 'MyRole') {
# do stuff here, like calling DSC Resources
MyCompositeResource StuffForMyRole {
# ...
}
}
View PSDSC_Config.ps1
configuration MyConfig {
Param()
if($Node.Role -contains 'DHCPData' -and $Node.Customers -eq 'CustomerA') {
$Domain = $ConfigurationData.customerA.Domain
}
else {
$Domain = $ConfigurationData.DefaultDomain.Domain
}
File MyDomainFile {
Ensure = 'Present'
View PseudoSplattingDsc.ps1
#Assuming you already have this hashtable
$MyHashes = @(
@{
Ensure = 'Present'
Name = 'Putty'
Version = 'Latest'
ChocolateyOptions = @{ source = 'https://chocolatey.org/api/v2/' }
},
@{
Ensure = 'Absent'
View IteratingResources.ps1
#Assuming you already have this hashtable
$MyHashes = @(
@{
Ensure = 'Present'
Name = 'Putty'
Version = 'Latest'
ChocolateyOptions = @{ source = 'https://chocolatey.org/api/v2/' }
},
@{
Ensure = 'Absent'
View DSC+hashtable.ps1
#Assuming you already have this hashtable
$MyHash = @{
Ensure = 'Present'
Name = 'Putty'
Version = 'Latest'
ChocolateyOptions = @{ source = 'https://chocolatey.org/api/v2/' }
}
Configuration MyDscConfig {
$Allnodes.nodename {