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
function Global:Get-DscSplattedResource {
[CmdletBinding()]
Param(
[String]
$ResourceName,
[String]
$ExecutionName,
[hashtable]
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
}
}
Configuration MyDSCConfig {
Node $ConfigurationData.AllNodes.nodename {
if($Node.roles -contains 'MyRole') {
# do stuff here, like calling DSC Resources
MyCompositeResource StuffForMyRole {
# ...
}
}
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'
#Assuming you already have this hashtable
$MyHashes = @(
@{
Ensure = 'Present'
Name = 'Putty'
Version = 'Latest'
ChocolateyOptions = @{ source = 'https://chocolatey.org/api/v2/' }
},
@{
Ensure = 'Absent'
#Assuming you already have this hashtable
$MyHashes = @(
@{
Ensure = 'Present'
Name = 'Putty'
Version = 'Latest'
ChocolateyOptions = @{ source = 'https://chocolatey.org/api/v2/' }
},
@{
Ensure = 'Absent'
#Assuming you already have this hashtable
$MyHash = @{
Ensure = 'Present'
Name = 'Putty'
Version = 'Latest'
ChocolateyOptions = @{ source = 'https://chocolatey.org/api/v2/' }
}
Configuration MyDscConfig {
$Allnodes.nodename {
Configuration MyDscConfig {
$Allnodes.nodename {
ChocolateyPackage Putty {
Ensure = 'Present'
Name = 'Putty'
Version = 'Latest'
ChocolateyOptions = @{ source = 'https://chocolatey.org/api/v2/' }
}
}
}
Function Export-StructuralUnitTestFromCommand {
param(
[parameter(Mandatory=$true,ValueFromPipelineByPropertyName = $true,ValueFromPipeline = $true)]
[System.Management.Automation.CommandInfo[]]
$command
)
begin {
$stringBuilder = New-object -TypeName System.Text.StringBuilder
$BuiltInParameters = ([Management.Automation.PSCmdlet]::CommonParameters + [Management.Automation.PSCmdlet]::OptionalCommonParameters)
}
@gaelcolas
gaelcolas / runKilaSuitWMF5Install.ps1
Created July 9, 2016 21:18
Running Ryan Rates install WMF5 from github
Invoke-Expression (New-Object Net.WebClient).DownloadString(‘https://raw.githubusercontent.com/kilasuit/PoshFunctions/Dev/Scripts/Install-WMF5.ps1’)