Skip to content

Instantly share code, notes, and snippets.

View bgelens's full-sized avatar

Ben Gelens bgelens

View GitHub Profile
# completed example
<#
.SYNOPSIS
Template for creating DSC Resource Unit Tests
.DESCRIPTION
To Use:
1. Copy to \Tests\Unit\ folder and rename <ResourceName>.tests.ps1 (e.g. MSFT_xFirewall.tests.ps1)
2. Customize TODO sections.
3. Delete all template comments (TODOs, etc.)
function Get-TargetResource
{
[CmdletBinding()]
[OutputType([System.Collections.Hashtable])]
param
(
[parameter(Mandatory = $true)]
[ValidateSet("Yes")]
[System.String]
$IsSingleInstance,
function Test-ClassResource
{
param(
[Parameter(ValueFromPipeline=$True,Mandatory=$True)]
[string]$fileName
)
$ast = [System.Management.Automation.Language.Parser]::ParseFile($fileName, [ref]$null, [ref]$null)
$result = foreach ($item in $ast.FindAll({$args[0] -is [System.Management.Automation.Language.AttributeAst]}, $false))
{
#requires -Version 3
function Get-PowerPlan {
<#
.SYNOPSIS
Display PowerPlans on requested machines.
.DESCRIPTION
Display PowerPlans on requested machines using CIM.
.PARAMETER ComputerName
ComputerNames to query for PowerPlans.
Default value is the local computername through $env:COMPUTERNAME
@bgelens
bgelens / Get-OsInfo.ps1
Created September 28, 2016 18:31
Parse os-release into object
function Get-OSInfo {
[cmdletbinding(DefaultParameterSetName='Brief')]
param (
[Parameter(ParameterSetName='Full')]
[Switch] $Full
)
process {
$osInfoFull = (Get-Content -Path /etc/os-release).Replace('"','') | ConvertFrom-StringData
if ($PSCmdlet.ParameterSetName -eq 'Brief') {
$osInfoFull.PRETTY_NAME
Install-Module -Name xPSDesiredStateConfiguration -Force
[DscLocalConfigurationManager()]
configuration LCM {
Settings {
RebootNodeIfNeeded = $true
ActionAfterReboot = 'ContinueConfiguration'
}
}
#region setup
$WorkingDir = $psISE.CurrentFile.FullPath | Split-Path
Set-Location $WorkingDir
#Add-AzureRmAccount
$AAAcct = Get-AzureRmAutomationAccount -Name DSCDemo01 -ResourceGroupName DSCDemo01
function Wait-AADSCCompileJob {
param (
[parameter(Mandatory,ValueFromPipeline)]
[Microsoft.Azure.Commands.Automation.Model.CompilationJob] $CompileJob,
#region setup
$WorkingDir = $psISE.CurrentFile.FullPath | Split-Path
Set-Location $WorkingDir
#Add-AzureRmAccount
$AAAcct = Get-AzureRmAutomationAccount -Name DSCDemo01 -ResourceGroupName DSCDemo01
$Keys = $AAAcct | Get-AzureRmAutomationRegistrationInfo
$RG = Get-AzureRmResourceGroup -Name DSCNodes
$StorageAccountName = 'dscnodes4588'
$Location = 'westeurope'
#endregion
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"vmName": {
"type": "string",
"metadata": {
"description": "Name of the existing VM to onboard into Azure Automation DSC"
}
},
#region setup
$WorkingDir = $psISE.CurrentFile.FullPath | Split-Path
Set-Location $WorkingDir
Add-AzureRmAccount
$AAAcct = Get-AzureRmAutomationAccount -Name DSCDemo01 -ResourceGroupName DSCDemo01
#endregion
#region list local VMs
Get-VM | Where-Object -FilterScript {$_.State -eq 'Running'}
#endregion