Skip to content

Commit 1447b60

Browse files
authored
Merge branch 'development' into minime
2 parents 7f235ad + 30c1c32 commit 1447b60

File tree

5 files changed

+232
-1
lines changed

5 files changed

+232
-1
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
param (
2+
$Path
3+
)
4+
5+
New-PSMDTemplate -ReferencePath "$PSScriptRoot" -OutPath $Path
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
@{
2+
TemplateName = 'dscclass'
3+
Version = "1.0.0.0"
4+
AutoIncrementVersion = $true
5+
Tags = 'dscresource'
6+
Author = 'Jan-Hendrik Peters'
7+
Description = 'Basic class-based DSC resource template with support for Azure Guest Configuration'
8+
Exclusions = @("PSMDInvoke.ps1") # Contains list of files - relative path to root - to ignore when building the template
9+
Scripts = @{
10+
guid = {
11+
[System.Guid]::NewGuid().ToString()
12+
}
13+
year = {
14+
Get-Date -Format "yyyy"
15+
}
16+
}
17+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
@{
2+
# Script module or binary module file associated with this manifest
3+
RootModule = 'þnameþ.psm1'
4+
5+
# Version number of this module.
6+
ModuleVersion = '1.0.0'
7+
8+
# ID used to uniquely identify this module
9+
GUID = 'þ!guid!þ'
10+
11+
# Author of this module
12+
Author = 'þauthorþ'
13+
14+
# Company or vendor of this module
15+
CompanyName = 'þcompanyþ'
16+
17+
# Copyright statement for this module
18+
Copyright = 'Copyright (c) þ!year!þ þauthorþ'
19+
20+
# Description of the functionality provided by this module
21+
Description = 'þdescriptionþ'
22+
23+
# Minimum version of the Windows PowerShell engine required by this module
24+
PowerShellVersion = '5.0'
25+
26+
# Modules that must be imported into the global environment prior to importing
27+
# this module
28+
# RequiredModules = @()
29+
30+
# Assemblies that must be loaded prior to importing this module
31+
# RequiredAssemblies = @('bin\þnameþ.dll')
32+
33+
# Type files (.ps1xml) to be loaded when importing this module
34+
# TypesToProcess = @('xml\þnameþ.Types.ps1xml')
35+
36+
# Format files (.ps1xml) to be loaded when importing this module
37+
# FormatsToProcess = @('xml\þnameþ.Format.ps1xml')
38+
39+
# Functions to export from this module
40+
FunctionsToExport = ''
41+
42+
# Cmdlets to export from this module
43+
# CmdletsToExport = ''
44+
45+
# Variables to export from this module
46+
# VariablesToExport = ''
47+
48+
# Aliases to export from this module
49+
# AliasesToExport = ''
50+
51+
DscResourcesToExport = @(
52+
'þnameþ'
53+
)
54+
55+
# List of all modules packaged with this module
56+
ModuleList = @()
57+
58+
# List of all files packaged with this module
59+
FileList = @()
60+
61+
# Private data to pass to the module specified in ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell.
62+
PrivateData = @{
63+
64+
#Support for PowerShellGet galleries.
65+
PSData = @{
66+
67+
# Tags applied to this module. These help with module discovery in online galleries.
68+
# Tags = @()
69+
70+
# A URL to the license for this module.
71+
# LicenseUri = ''
72+
73+
# A URL to the main website for this project.
74+
# ProjectUri = ''
75+
76+
# A URL to an icon representing this module.
77+
# IconUri = ''
78+
79+
# ReleaseNotes of this module
80+
# ReleaseNotes = ''
81+
82+
} # End of PSData hashtable
83+
84+
} # End of PrivateData hashtable
85+
}
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
enum Ensure
2+
{
3+
Present
4+
Absent
5+
}
6+
7+
# Support for DSC v3, or Azure Guest Configuration
8+
class Reason
9+
{
10+
[DscProperty()]
11+
[string] $Code
12+
13+
[DscProperty()]
14+
[string] $Phrase
15+
}
16+
17+
function Get-Resource
18+
{
19+
[OutputType([hashtable])]
20+
[CmdletBinding()]
21+
param
22+
(
23+
)
24+
25+
$reasonList = @()
26+
27+
if ($Ensure -eq 'Present' -and -not $successfulTests)
28+
{
29+
$reasonList += @{
30+
Code = 'þnameþ:þnameþ:SomethingAwfulHappened'
31+
Phrase = "Extend the reasonList with all errors"
32+
}
33+
}
34+
35+
return @{
36+
Reasons = $reasonList
37+
}
38+
}
39+
40+
function Set-Resource
41+
{
42+
[CmdletBinding()]
43+
param
44+
(
45+
)
46+
47+
}
48+
49+
function Test-Resource
50+
{
51+
[OutputType([bool])]
52+
[CmdletBinding()]
53+
param
54+
(
55+
56+
)
57+
58+
return $true
59+
}
60+
61+
[DscResource()]
62+
class þnameþ
63+
{
64+
[DscProperty(Key)] [string] $YourKeyProperty
65+
[DscProperty(Mandatory)] [string] $YourRequiredProperty
66+
[DscProperty()] [string[]] $YourStandardProperty
67+
[DscProperty()] [Ensure] $Ensure # Usually a good idea to include
68+
[DscProperty(NotConfigurable)] [Reason[]] $Reasons # Reserved for Azure Guest Configuration
69+
70+
þnameþ ()
71+
{
72+
$this.Ensure = 'Present' # Set up defaults
73+
}
74+
75+
[þnameþ] Get()
76+
{
77+
$parameter = $this.GetConfigurableDscProperties()
78+
return (Get-Resource @parameter)
79+
}
80+
81+
[void] Set()
82+
{
83+
$parameter = $this.GetConfigurableDscProperties()
84+
Set-Resource @parameter
85+
}
86+
87+
[bool] Test()
88+
{
89+
$parameter = $this.GetConfigurableDscProperties()
90+
return (Test-Resource @parameter)
91+
}
92+
93+
[Hashtable] GetConfigurableDscProperties()
94+
{
95+
# This method returns a hashtable of properties with two special workarounds
96+
# The hashtable will not include any properties marked as "NotConfigurable"
97+
# Any properties with a ValidateSet of "True","False" will beconverted to Boolean type
98+
# The intent is to simplify splatting to functions
99+
# Source: https://gist.github.com/mgreenegit/e3a9b4e136fc2d510cf87e20390daa44
100+
$DscProperties = @{}
101+
foreach ($property in [þnameþ].GetProperties().Name)
102+
{
103+
# Checks if "NotConfigurable" attribute is set
104+
$notConfigurable = [þnameþ].GetProperty($property).GetCustomAttributes($false).Where({ $_ -is [System.Management.Automation.DscPropertyAttribute] }).NotConfigurable
105+
if (!$notConfigurable)
106+
{
107+
$value = $this.$property
108+
# Gets the list of valid values from the ValidateSet attribute
109+
$validateSet = [þnameþ].GetProperty($property).GetCustomAttributes($false).Where({ $_ -is [System.Management.Automation.ValidateSetAttribute] }).ValidValues
110+
if ($validateSet)
111+
{
112+
# Workaround for boolean types
113+
if ($null -eq (Compare-Object @('True', 'False') $validateSet))
114+
{
115+
$value = [System.Convert]::ToBoolean($this.$property)
116+
}
117+
}
118+
# Add property to new
119+
$DscProperties.add($property, $value)
120+
}
121+
}
122+
return $DscProperties
123+
}
124+
}

templates/PSFProject/azure-pipelines.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
pool:
2-
name: Hosted VS2017
2+
vmImage: "windows-latest"
33
steps:
44
- task: PowerShell@2
55
displayName: Prerequisites

0 commit comments

Comments
 (0)