Skip to content

Instantly share code, notes, and snippets.

View dlwyatt's full-sized avatar

Dave Wyatt dlwyatt

  • Ontario, Canada
  • 05:33 (UTC -04:00)
  • X @MSH_Dave
View GitHub Profile
@dlwyatt
dlwyatt / AsyncTests.ps1
Created May 29, 2014 03:55
JobScript update
$JobScript = @"
&{
`$DebugPreference = 'Continue'
Write-Debug "Start(Ticks) = `$((get-date).Ticks)"
}
& { $ScriptBlock } @args
&{
`$DebugPreference = 'Continue'
@dlwyatt
dlwyatt / AlternativeDynamicParamMethod.ps1
Created September 4, 2014 12:08
DynamicParam class example
Add-Type -TypeDefinition @'
using System;
using System.Management.Automation;
public class DynamicParamExample
{
[Parameter()]
[ValidateSet("one", "two", "three")]
public string MyDynamicParameter { get; set; }
}
@dlwyatt
dlwyatt / ResolveConfigurationData-Original.ps1
Last active September 26, 2016 18:35
Resolve ConfigurationData updates
if (-not $PSBoundParameters.ContainsKey('ConfigurationData')) {
Write-Verbose ""
Write-Verbose "Resolving ConfigurationData"
$ScopeToCheck = 1
do {
try {
$ConfigurationData = Get-Variable -scope $ScopeToCheck -Name 'ConfigurationData' -ValueOnly -ErrorAction Stop
}
catch {
Write-Verbose "`t`tNothing in scope $ScopeToCheck for ConfigurationData"
@dlwyatt
dlwyatt / Resolve-DscConfigurationPropertyUpdate.ps1
Created September 24, 2014 00:39
Resolve-DscConfigurationProperty update
$ConfigurationData = @{
AllNodes = @(
@{
NodeName = 'Server01'
Applications = @{
Mercurial = @{
Name = 'Mercurial 2.5.1 (x64)'
ProductId = 'F39802E0-BE92-4896-A67B-85144CF01831'
SourcePath = '\\servername\sharename\Mercurial\'
Installer = 'mercurial-2.5.1-x64.msi'
$configData = @{
AllNodes = @(
@{
NodeName = '*'
AllNodesProperty = 'AllNodesValue'
}
@{
NodeName = 'Node1'
FilterNumber = 1
@dlwyatt
dlwyatt / Braces.ps1
Last active August 29, 2015 14:11
Comparing brace styles with long, multi-line conditions.
if ($reallyLongConditionThatIDontFeelLikeMakingUpRightNowSoIllJustUseAVariableNameNumberOne -and
$reallyLongConditionThatIDontFeelLikeMakingUpRightNowSoIllJustUseAVariableNameNumberTwo) {
Do-Something
}
# Versus:
if ($reallyLongConditionThatIDontFeelLikeMakingUpRightNowSoIllJustUseAVariableNameNumberOne -and
$reallyLongConditionThatIDontFeelLikeMakingUpRightNowSoIllJustUseAVariableNameNumberTwo)
{
@dlwyatt
dlwyatt / ugly.ps1
Created December 26, 2014 01:22
PSD1 import ugliness
$utilsType = [scriptblock].Assembly.GetType('System.Management.Automation.PsUtils')
$flags = [System.Reflection.BindingFlags]'Instance, Static, Nonpublic'
$method = $utilsType.GetMethod('EvaluatePowerShellDataFileAsModuleManifest', $flags)
$context = $ExecutionContext.GetType().GetField('_context', $flags).GetValue($ExecutionContext)
$path = (gmo bitstransfer -list).Path
$hashTable = $method.Invoke($null, @($null, $path, $context, $true))
$hashTable
@dlwyatt
dlwyatt / Snake.ps1
Created December 31, 2014 19:34
Snake update
#requires -version 2
#
# Powershell Snake Game
# Author : Kurt Jaegers
#
function SetEmptySquare($x, $y)
{
$matrix[$x, $y] = $emptysquare
@dlwyatt
dlwyatt / example.Tests.ps1
Created February 14, 2015 13:25
Pester Example
# Import the stuff you'll be testing. Could be dot-sourcing a ps1 file here, importing a module, whatever you need.
# If importing a mdoule, make sure you've only got one copy of it imported, or weird things can happen when you start
# to get into mocking.
Remove-Module [S]omeDscResource
Import-Module $PSScriptRoot\SomeDscResource.psm1
# All of the Pester tests in a script must go inside a Describe block; you can mave many Describe blocks in the same
# script, if you like. Make sure to put the opening brace on the same line as Describe, since this is just a function
# pretending to be a keyword; no assistance from the parser allowing us to put opening braces on their own lines.
@dlwyatt
dlwyatt / ConvertTo-Hashtable.ps1
Created March 5, 2015 14:40
ConvertTo-Hashtable
function ConvertTo-Hashtable
{
[CmdletBinding()]
param (
[Parameter(Mandatory = $true, ValueFromPipeline = $true)]
[psobject[]] $InputObject
)
process
{