Skip to content

Instantly share code, notes, and snippets.

View bgelens's full-sized avatar

Ben Gelens bgelens

View GitHub Profile
Install-Module -Name xPSDesiredStateConfiguration -Force
[DscLocalConfigurationManager()]
configuration LCM {
Settings {
RebootNodeIfNeeded = $true
ActionAfterReboot = 'ContinueConfiguration'
}
}
@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
#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
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))
{
function Get-TargetResource
{
[CmdletBinding()]
[OutputType([System.Collections.Hashtable])]
param
(
[parameter(Mandatory = $true)]
[ValidateSet("Yes")]
[System.String]
$IsSingleInstance,
# 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.)
#region localizeddata
if (Test-Path "${PSScriptRoot}\${PSUICulture}")
{
Import-LocalizedData `
-BindingVariable LocalizedData `
-Filename MSFT_LMHost.psd1 `
-BaseDirectory "${PSScriptRoot}\${PSUICulture}"
}
else
{
New-xDscResource -ModuleName NetworkingDsc -Name MSFT_LMHost -FriendlyName LMHost -ClassVersion 1.0.0.0 -Path ..\Demo -Property @(
New-xDscResourceProperty -Name IsSingleInstance -Attribute Key -Type String -ValidateSet 'Yes' -Description "This is a system wide setting and can only be applied once"
New-xDscResourceProperty -Name Enable -Type Boolean -Attribute Required -Description "This will Enable or Disable LMHost lookup"
)
// Place your settings in this file to overwrite the default settings
{
"terminal.integrated.shell.windows": "C:\\WINDOWS\\sysnative\\WindowsPowerShell\\v1.0\\powershell.exe",
"editor.renderWhitespace": "boundary",
"workbench.activityBar.visible": true,
"window.zoomLevel": 3,
"terminal.integrated.fontFamily": "monofur for Powerline",
"editor.tabSize": 4,
"editor.detectIndentation": false,
"files.associations": {
# first test
Describe 'MSFT_LMHost\Test-TargetResource' {
Context 'Invoking with LMHost currently enabled' {
Mock -CommandName 'Test-LMHostEnabled' -MockWith {return $true}
It 'Should return "true" when Enable is set to "true" and current state is "true"' {
Test-TargetResource -IsSingleInstance 'Yes' -Enable $true | Should Be $true
}
It 'Should return "false" when Enable is set to "false" and current state is "true"' {
Test-TargetResource -IsSingleInstance 'Yes' -Enable $false | Should Be $false