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
class Requirement { | |
[string] $Name | |
[scriptblock] $Test | |
[scriptblock] $Set | |
} | |
$mySystem = [System.Collections.ArrayList]::new() | |
$requirements = [Requirement[]]@( | |
@{ |
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
enum MyAutocompleteValues { | |
A, | |
B, | |
C | |
} | |
# initialize values once instead of on every invokation | |
$someDynamicSetting = ... | |
function myHelperFunction($a, $b) { |
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 Test-Node { | |
[CmdletBinding()] | |
Param( | |
[Parameter(Mandatory, ParameterSetName = "Nodes", ValueFromPipeline)] | |
[ValidateNotNullOrEmpty()] | |
[string[]] $Node, | |
[Parameter(Mandatory, ParameterSetName = "File")] | |
[ValidateSet( { Test-Path $_ })] | |
[ValidateNotNullOrEmpty()] |
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 testNode([string]$Id) { | |
try { | |
Invoke-RestMethod -Method Get -Uri "https://$Id/test" | |
$auditResult = $true | |
} catch { | |
$auditResult = $false | |
} | |
[AuditResult]@{ | |
Healthy = $auditResult | |
Computer = $Id |
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
class Computer { | |
[string] $Service | |
[string] $ClusterId | |
[string] $DatacenterId | |
[string] $Id | |
Computer([string]$Id) { | |
$this.Id = $Id | |
if ($Id -notmatch "(\w+)(\d+)(\w+\d+)") { | |
throw "Invalid Computer ID '$Id'" | |
} |
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-Module MyModule |
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
$modulesDir = $env:PSModulePath -split ":" | Select -First 1 | |
Move-Item .\MyModule $modulesDir |
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
SHELL pwsh | |
ENV PSModulePath="$PSModulePath:/modules" | |
COPY ./MyModule /modules | |
RUN Import-Module MyModule; Invoke-FunctionInMyModule |
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
$env:PSModulePath -split ":" ` | |
| Get-ChildItem -Filter *.psd1 -Recurse ` | |
| Import-PowerShellDataFile -ErrorAction SilentlyContinue ` | |
| % {$_["RequiredModules"]} ` | |
| % {@{Name = $_["ModuleName"]; RequiredVersion = $_["ModuleVersion"]}} ` | |
| ? {-not (Get-Module @_ -ListAvailable)} ` | |
| % {Install-Module @_} |
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
PS /projects> mkdir MyModule | |
PS /projects> cd MyModule | |
PS /projects/MyModule> |