Skip to content

Instantly share code, notes, and snippets.

View gaelcolas's full-sized avatar
🏠
Working from home

Gael gaelcolas

🏠
Working from home
View GitHub Profile
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'
Configuration MyDSCConfig {
Node $ConfigurationData.AllNodes.nodename {
if($Node.roles -contains 'MyRole') {
# do stuff here, like calling DSC Resources
MyCompositeResource StuffForMyRole {
# ...
}
}
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
}
}
function Global:Get-DscSplattedResource {
[CmdletBinding()]
Param(
[String]
$ResourceName,
[String]
$ExecutionName,
[hashtable]
$ConfigurationData = @{
AllNodes = @(
@{
Nodename = 'SRV01'
Role = 'ServerType1_Application'
},
@{
Nodename = 'SRV02'
Role = 'ServerType2_Application'
}
@gaelcolas
gaelcolas / new_unattend_iso.ps1
Created July 9, 2016 21:45
create ISO with my Unattend.xml file
. '.\TestKitchen\script\IsoFile.ps1'
#create ISO with my Unattend.xml file
New-IsoFile -Source .\TestKitchen\Unattend.xml -Path .\TestKitchen\Unattendxml.iso -Force -Title MyISO
@gaelcolas
gaelcolas / Invoke-TestHandlerAction.ps1
Created November 7, 2018 09:49
Example of a Datum handler that can reference another datum based on its path (rough and dirty)
function Invoke-TestHandlerAction {
Param(
$Password,
$test,
$Datum,
$Node,
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)
@gaelcolas
gaelcolas / DynamicParam.draft.ps1
Last active August 1, 2019 16:30
PowerShell Generating dynamic parameters and parameter sets to wrap around a Class for easy instantiation such as new-Type -ctorArg1 $val -property $val2
#region Get-TypeDynamicParam
function Get-DynamicParamFromTypeName {
Param(
[string]
$TypeName
)
function New-ParamAttribute {
Param(
[Parameter(Mandatory=$true,ValueFromPipeLine=$false,ValueFromPipelineByPropertyName=$true, position=0)]
[string]
@gaelcolas
gaelcolas / dummy jinja composite.ps1
Created April 22, 2021 15:51
basic jinja composite with explicit parameters
Configuration MyComposite {
Params (
$TemplateFilePath = 'MyJinja2Template.tpl',
$parameter1,
$parameter2
)
$tempParamFile = [io.Path]::GetTempFileName()