Last active
May 10, 2023 13:09
-
-
Save dancing-groot/caba8c6305cd776df997e15de6e1889a to your computer and use it in GitHub Desktop.
PowerShell Script Layout - Based on https://poshcode.gitbook.io/powershell-practice-and-style/introduction/readme and https://adamtheautomator.com/ppowershell-pipeline/
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
<# | |
.SYNOPSIS | |
A brief description of the function or script | |
.DESCRIPTION | |
A longer description | |
.NOTES | |
Version: yyyy.mm.dd | |
Author: Author Name | |
Info: Release Notes | |
#> | |
[cmdletBinding()] | |
param() | |
#region FUNCTIONS | |
function Test-Function | |
{ | |
[cmdletBinding()] | |
param | |
( | |
[Parameter(ValueFromPipeline,ValueFromPipelinebyPropertyName)] | |
[int[]]$MyVar = 0 | |
) | |
begin | |
{ | |
if ($PSBoundParameters['Debug']) { $DebugPreference = 'Continue' } | |
} | |
process | |
{ | |
foreach ($variable in $MyVar) | |
{ | |
Write-Debug "Testing $variable" | |
if ($variable -eq 1) | |
{ | |
$true | |
} | |
else | |
{ | |
$false | |
} | |
} | |
} | |
} # Test-Function | |
#endregion FUNCTIONS | |
#region DECLARATION | |
$Var = 1 | |
#endregion DECLARATION | |
#region MAIN | |
Write-Host "Calling function with no argument: $(Test-Function)" | |
Write-Host "Calling function with argument value `$Var: $(Test-Function -MyVar $Var)" | |
Write-Host "First pipe test:" | |
0,1,2,"a" | Test-Function -Debug -ErrorAction SilentlyContinue | |
Write-Host "Second pipe test:" | |
Test-Function -MyVar -1,0,1 | |
#endregion MAIN |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment