My Profile Photo Title

Thoughts about DevOps and automation from a Windows guy


POSHOrigin - Defaults File feature image

POSHOrigin - Defaults File

This article is Part 4 in a 9-Part series about POSHOrigin, a PowerShell module that aims to assist you in managing your Infrastructure via custom PowerShell DSC resources.

POSHOrigin on GitHub→

Defaults File

The defaults file is where you can store common resource configuration data that will be shared across multiple configurations. When each resource block in your configuration is processed, if it specifies a defaults file, those defaults will be converted into a hashtable that will get merged with the hashtable of the resource. If there are any duplicates between the defaults file and the resource block, the values from the resource block will be used.

file_defaults.psd1
1
2
3
4
5
@{
    ensure = 'present'
    path = 'c:\'
    contents = 'this is some content'
}
files.ps1
1
2
3
resource 'example:poshfile' 'file1.txt' @{
    defaults = '.\file_defaults.psd1'
}

The examples above are the equivalent of specifying all options in the configuration file.

create_file.ps1
1
2
3
4
5
resource 'example:poshfile' 'file1.txt' @{
    ensure = 'present'
    path = 'c:\'
    contents = 'this is some content'
}

Cheers

Show your support

Become a GitHub Sponsor
Become a Patron

Like books? Check these out!

You might also like:

Sharing is caring