Show pageOld revisionsBacklinksBack to top This page is read only. You can view the source, but not change it. Ask your administrator if you think this is wrong. ====== Powershell Examples ====== * code snippets * [[https://gist.github.com/9to5IT/dbc91fea726c113fad6c|Basic Template (w/ logging)]] * [[https://learn.microsoft.com/en-us/powershell/scripting/developer/help/examples-of-comment-based-help?view=powershell-7.2|Comment-based Help]] ====== Common Script Structure ====== ==== Basic script with parameters ==== <code powershell> param( [Parameter(Mandatory=$true)] [String]$src = "alpha", [Parameter(Mandatory=$true)] [String]$dest = "beta", [Parameter(Mandatory=$false)] [switch]$recurse ) function main { Write-Host $recurse Write-Host $src Write-Host $dest } main </code> === Alt Format === <code powershell> param( [Parameter(Mandatory=$true)] [string] $src = "alpha", [Parameter(Mandatory=$true)] [string] $dest = "beta", [Parameter(Mandatory=$false)] [switch] $recurse ) function main { Write-Host $recurse Write-Host $src Write-Host $dest } main </code> ====== Loop Over Files ====== === Example of looping over files and doing something with them === <code powershell> param( [Parameter(Mandatory=$true)] [String]$dir ) foreach ($file in Get-ChildItem -File $dir) { jq -s -f .\filter.jq $dir\$file } </code> powershell_examples.txt Last modified: 2023/01/30 13:48by mgupton