forked from devops-collective-inc/PSHSummit2023
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Copy from jaykul/DevOps2023-Practices
- Loading branch information
Showing
22 changed files
with
1,308 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export/ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
|
||
default: true | ||
MD003: | ||
style: "atx" | ||
MD022: | ||
lines_above: 1 | ||
lines_below: 1 | ||
MD025: false | ||
MD013: false | ||
MD033: false | ||
MD007: | ||
indent: 4 | ||
no-hard-tabs: false |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# These three functions show how sometimes an -ErrorAction Ignore can surpress an exception ... | ||
# But have it bubble up again later when someone tries a trap or try/catch | ||
function divide { | ||
[CmdletBinding()] | ||
param($numerator = 1, $denominator = 0) | ||
$numerator / $denominator | ||
} | ||
|
||
function nevercrash { | ||
[CmdletBinding()] | ||
param($numerator = 1, $denominator = 0) | ||
divide @PSBoundParameters -ErrorAction Ignore | ||
} | ||
|
||
function surprise { | ||
[CmdletBinding()] | ||
param($ammount = 1) | ||
try { | ||
nevercrash $ammount | ||
} catch { | ||
throw $_ | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
function Import-Configuration { | ||
<# | ||
.SYNOPSIS | ||
TODO | ||
.EXAMPLE | ||
TODO | ||
#> | ||
[CmdletBinding()] | ||
param( | ||
# TODO | ||
[Parameter(ValueFromPipelineByPropertyName)] | ||
$TODO | ||
) | ||
process { | ||
try { | ||
# TODO | ||
} catch { | ||
throw $_ | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# A basic prompt | ||
function prompt { | ||
"`e[36m$($MyInvocation.HistoryId)`e[37m $pwd`e[0m`n$([char]0x276f)" | ||
} | ||
|
||
# When there are errors in your prompt | ||
function prompt { | ||
Write-Error "Typo"; | ||
"`e[36m$($MyInvocation.HistoryId)`e[37m $pwd`e[0m`n$([char]0x276f)" | ||
} | ||
|
||
# When there's an exception in your prompt | ||
function prompt { | ||
Write-Error "Typo" | ||
"`e[36m$($MyInvocation.HistoryId)`e[37m $pwd`e[0m`n$([char]0x276f)" | ||
throw "grenade" | ||
} | ||
|
||
# You should know to check ... | ||
$Error[0..2] | ||
|
||
# Let's look at how PowerLine handles it: | ||
Set-PowerLinePrompt | ||
|
||
# Your prompt is an array of scriptblocks | ||
$prompt | ||
|
||
# We can add an error to it | ||
Add-PowerLineBlock { Write-Error "Typo"} | ||
|
||
# We can hide that warning output: | ||
Set-PowerLinePrompt -HideErrors | ||
|
||
# Even if it's an exception! | ||
Add-PowerLineBlock { throw "grenades" } | ||
|
||
# Hiding it is probably a bad idea | ||
Set-PowerLinePrompt -HideErrors:$False | ||
|
||
# So let's look at the errors | ||
# We can see which block caused them | ||
$PromptErrors | ||
|
||
# And look more closely at the exception | ||
$PromptErrors[1] | fl * -fo | ||
|
||
# Then we can put our prompt back | ||
Remove-PowerLineBlock { Write-Error "Typo" } | ||
Remove-PowerLineBlock { throw "grenades" } |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[CmdletBinding()] | ||
param( | ||
[switch]$PleaseDontThrow | ||
) | ||
|
||
try { | ||
Write-Information "Enter $($MyInvocation.MyCommand)" -Tag Trace | ||
if (!$PleaseDontThrow) { | ||
Write-Information "`$PleaseDontThrow was $PleaseDontThrow, so ..." -Tag Trace | ||
throw "horseshoes" | ||
} | ||
} catch { | ||
Write-Information $_ -Tag Exception | ||
throw $_ | ||
} | ||
Write-Information "Exit $($MyInvocation.Line)" -Tag Trace |
35 changes: 35 additions & 0 deletions
35
Joel-Bennett-Tempting-Fate/demo/04. Import-Configuration.ps1
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
function Import-Configuration { | ||
<# | ||
.SYNOPSIS | ||
A command to load configuration for a module | ||
.EXAMPLE | ||
$Config = Import-Configuration | ||
Load THIS module's configuration from a command | ||
.EXAMPLE | ||
$Config = Import-Configuration | ||
$Config.AuthToken = $ShaToken | ||
$Config | Export-Configuration | ||
Update a single setting in the configuration | ||
.EXAMPLE | ||
$Config = Get-Module PowerLine | Import-Configuration | ||
$Config.PowerLineConfig.DefaultAddIndex = 2 | ||
Get-Module PowerLine | Export-Configuration $Config | ||
Update a single setting in the configuration | ||
#> | ||
[CmdletBinding()] | ||
param( | ||
# The module to import configuration from | ||
[Parameter(ValueFromPipelineByPropertyName, ValueFromPipeline, Mandatory)] | ||
[System.Management.Automation.PSModuleInfo]$Module | ||
) | ||
process { | ||
try { | ||
# TODO | ||
} catch { | ||
throw $_ | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
Joel-Bennett-Tempting-Fate/demo/05. ArgumentTransformation.ps1
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class ModuleInfoAttribute : System.Management.Automation.ArgumentTransformationAttribute { | ||
[object] Transform([System.Management.Automation.EngineIntrinsics]$engineIntrinsics, [object] $inputData) { | ||
$ModuleInfo = $null | ||
if ($inputData -is [string] -and -not [string]::IsNullOrWhiteSpace($inputData)) { | ||
$ModuleInfo = Get-Module $inputData -ErrorAction SilentlyContinue | ||
if (-not $ModuleInfo) { | ||
$ModuleInfo = @(Get-Module $inputData -ErrorAction SilentlyContinue -ListAvailable)[0] | ||
} | ||
} | ||
if (-not $ModuleInfo) { | ||
throw ([System.ArgumentException]"$inputData module could not be found, please try passing the output of 'Get-Module $InputData' instead") | ||
} | ||
return $ModuleInfo | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
Joel-Bennett-Tempting-Fate/demo/06. Import-Configuration.ps1
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using namespace System.Management.Automation | ||
|
||
class ModuleInfoAttribute : ArgumentTransformationAttribute { | ||
[object] Transform([EngineIntrinsics]$engineIntrinsics, [object] $inputData) { | ||
$ModuleInfo = $null | ||
if ($inputData -is [string] -and -not [string]::IsNullOrWhiteSpace($inputData)) { | ||
$ModuleInfo = Get-Module $inputData -ErrorAction SilentlyContinue | ||
if (-not $ModuleInfo) { | ||
$ModuleInfo = @(Get-Module $inputData -ErrorAction SilentlyContinue -ListAvailable)[0] | ||
} | ||
} | ||
if (-not $ModuleInfo) { | ||
throw ([System.ArgumentException]"$inputData module could not be found, please try passing the output of 'Get-Module $InputData' instead") | ||
} | ||
return $ModuleInfo | ||
} | ||
} | ||
|
||
function Import-Configuration { | ||
<# | ||
.SYNOPSIS | ||
A command to load configuration for a module | ||
.EXAMPLE | ||
$Config = Import-Configuration | ||
Load THIS module's configuration from a command | ||
.EXAMPLE | ||
$Config = Import-Configuration | ||
$Config.AuthToken = $ShaToken | ||
$Config | Export-Configuration | ||
Update a single setting in the configuration | ||
.EXAMPLE | ||
$Config = Get-Module PowerLine | Import-Configuration | ||
$Config.PowerLineConfig.DefaultAddIndex = 2 | ||
Get-Module PowerLine | Export-Configuration $Config | ||
Update a single setting in the configuration | ||
.EXAMPLE | ||
$Config = Import-Configuration -Name Powerline -CompanyName HuddledMasses.org | ||
Load the specififed module's configuration by hand | ||
#> | ||
[CmdletBinding()] | ||
param( | ||
# The module to import configuration from | ||
[Parameter(ValueFromPipelineByPropertyName, ValueFromPipeline, Mandatory)] | ||
[ModuleInfo()] | ||
[PSModuleInfo]$Module | ||
) | ||
process { | ||
try { | ||
|
||
$Path = Join-Path $Env:APPDATA ( | ||
Join-Path $Module.CompanyName $Module.Name | ||
) | ||
|
||
Import-LocalizedData -BaseDirectory $Path -FileName Configuration.psd1 | ||
|
||
} catch { | ||
throw $_ | ||
} | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.