Last active
March 13, 2016 11:06
-
-
Save rchaganti/bc7fc6e6c6509d93110f to your computer and use it in GitHub Desktop.
ISE Snippets for DSC Resources (PowerShell 4.0 and 5.0)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$GetTargetResource = @' | |
#TODO - Add the logic for Get-TagetResource | |
#TODO - Always return a hashtable from this function | |
#TODO - Remove $Ensure if it is not required | |
function Get-TargetResource | |
{ | |
[OutputType([Hashtable])] | |
param ( | |
[Parameter()] | |
[ValidateSet('Present','Absent')] | |
[string] | |
$Ensure = 'Present' | |
) | |
} | |
'@ | |
$SetTargetResource = @' | |
#TODO - Add the logic for Set-TargetResource | |
#TODO - Do not return any value from this function | |
#TODO - Remove $Ensure if it is not required | |
function Set-TargetResource | |
{ | |
param ( | |
[Parameter()] | |
[ValidateSet('Present','Absent')] | |
[string] | |
$Ensure = 'Present' | |
) | |
} | |
'@ | |
$TestTargetResource = @' | |
#TODO - Add the logic for Test-TargetResource | |
#TODO - Return only boolean value from this function | |
#TODO - Remove $Ensure if it is not required | |
function Test-TargetResource | |
{ | |
[OutputType([boolean])] | |
param ( | |
[parameter()] | |
[ValidateSet('Present','Absent')] | |
[string] | |
$Ensure = 'Present' | |
) | |
} | |
'@ | |
$DSCCompleteResource = @' | |
#TODO - Add the logic for Get-TagetResource | |
#TODO - Always return a hashtable from this function | |
#TODO - Remove $Ensure if it is not required | |
function Get-TargetResource | |
{ | |
[OutputType([Hashtable])] | |
param ( | |
[Parameter()] | |
[ValidateSet('Present','Absent')] | |
[string] | |
$Ensure = 'Present' | |
) | |
} | |
#TODO - Add the logic for Set-TargetResource | |
#TODO - Do not return any value from this function | |
#TODO - Remove $Ensure if it is not required | |
function Set-TargetResource | |
{ | |
param ( | |
[Parameter()] | |
[ValidateSet('Present','Absent')] | |
[string] | |
$Ensure = 'Present' | |
) | |
} | |
#TODO - Add the logic for Test-TargetResource | |
#TODO - Return only boolean value from this function | |
#TODO - Remove $Ensure if it is not required | |
function Test-TargetResource | |
{ | |
[OutputType([boolean])] | |
param ( | |
[parameter()] | |
[ValidateSet('Present','Absent')] | |
[string] | |
$Ensure = 'Present' | |
) | |
} | |
'@ | |
$DSCClassResource = @' | |
#TODO - Update ClassName with your resource name | |
#TODO - Remove Ensure enum if not required | |
#ToDO - Add the logic required for Get, Set, and Test functions | |
enum Ensure | |
{ | |
Absent | |
Present | |
} | |
[DscResource()] | |
class <ClassName> | |
{ | |
[Ensure] $Ensure | |
[void] Set() | |
{ | |
} | |
[bool] Test() | |
{ | |
} | |
[Hashtable] Get() | |
{ | |
} | |
} | |
'@ | |
New-IseSnippet -Title 'DSC Get-TargetResource' -Text $GetTargetResource -Description 'Get-TargetResource DSC function template' -Author 'PowerShell Magazine' -Force | |
New-IseSnippet -Title 'DSC Set-TargetResource' -Text $SetTargetResource -Description 'Set-TargetResource DSC function template' -Author 'PowerShell Magazine' -Force | |
New-IseSnippet -Title 'DSC Test-TargetResource' -Text $TestTargetResource -Description 'Test-TargetResource DSC function template' -Author 'PowerShell Magazine' -Force | |
New-IseSnippet -Title 'DSC Resource Function (Complete)' -Text $DSCCompleteResource -Description 'DSC Resource function templates (Complete)' -Author 'PowerShell Magazine' -Force | |
New-IseSnippet -Title 'DSC Class-defined DSC resource (PowerShell 5.0)' -Text $DSCClassResource -Description 'Class-defined DSC resource template' -Author 'PowerShell Magazine' -Force |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment