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
$JobScript = @" | |
&{ | |
`$DebugPreference = 'Continue' | |
Write-Debug "Start(Ticks) = `$((get-date).Ticks)" | |
} | |
& { $ScriptBlock } @args | |
&{ | |
`$DebugPreference = 'Continue' |
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
Add-Type -TypeDefinition @' | |
using System; | |
using System.Management.Automation; | |
public class DynamicParamExample | |
{ | |
[Parameter()] | |
[ValidateSet("one", "two", "three")] | |
public string MyDynamicParameter { get; set; } | |
} |
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
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" |
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
$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' |
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
$configData = @{ | |
AllNodes = @( | |
@{ | |
NodeName = '*' | |
AllNodesProperty = 'AllNodesValue' | |
} | |
@{ | |
NodeName = 'Node1' | |
FilterNumber = 1 |
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
if ($reallyLongConditionThatIDontFeelLikeMakingUpRightNowSoIllJustUseAVariableNameNumberOne -and | |
$reallyLongConditionThatIDontFeelLikeMakingUpRightNowSoIllJustUseAVariableNameNumberTwo) { | |
Do-Something | |
} | |
# Versus: | |
if ($reallyLongConditionThatIDontFeelLikeMakingUpRightNowSoIllJustUseAVariableNameNumberOne -and | |
$reallyLongConditionThatIDontFeelLikeMakingUpRightNowSoIllJustUseAVariableNameNumberTwo) | |
{ |
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
$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 |
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
#requires -version 2 | |
# | |
# Powershell Snake Game | |
# Author : Kurt Jaegers | |
# | |
function SetEmptySquare($x, $y) | |
{ | |
$matrix[$x, $y] = $emptysquare |
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
# 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. |
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
function ConvertTo-Hashtable | |
{ | |
[CmdletBinding()] | |
param ( | |
[Parameter(Mandatory = $true, ValueFromPipeline = $true)] | |
[psobject[]] $InputObject | |
) | |
process | |
{ |
OlderNewer