https://ss64.com/ps/syntax-functions.html
https://docs.microsoft.com/en-us/powershell/scripting/learn/ps101/09-functions?view=powershell-7
Note: When calling a PS1 script, it is read top-down and functions must be at the TOP.
https://stackoverflow.com/a/17347721/5079799
function Add-Numbers { $args[0] + $args[1] }
<ApprovedVerb>-<Prefix><SingularNoun>
function Test-DoesFileExistBool { param ( [ValidateSet(“Tom”,”Dick”,”Jane”)] [String] $Name ) Test-Path $FilePath 2> $null } $FExistBool = Test-DoesFileExistBool -FilePath $FilePath
function Compare-IsBoolTrue { param ( [string[]]$TFBool ) IF ($TFBool -eq "True") { Write-Host "File Found" } ELSE { Write-Host "File NOT Found" } } Compare-IsBoolTrue -TFBool $FExistBool Compare-IsBoolTrue -TFBool TRUE
function Output-SalesTax { param( [int]$Price, [int]$Tax ) $Price + $Tax } #$result = Add-Numbers (5, 10) --Wrong! $result = Output-SalesTax 5 10 #--Right echo $result #15
Get-Verb | Sort-Object -Property Group Verb Group ---- ----- Resize Common Reset Common Select Common Search Common Redo Common Push Common Rename Common Remove Common Set Common Undo Common Switch Common Watch Common Unlock Common Skip Common Show Common Step Common Split Common Exit Common Enter Common Format Common Find Common Clear Common Add Common Copy Common Close Common Get Common Open Common New Common Pop Common Optimize Common Join Common Hide Common Move Common Lock Common Read Communications Disconnect Communications Connect Communications Write Communications Send Communications Receive Communications Out Data Publish Data Merge Data Mount Data Restore Data Unpublish Data Update Data Save Data Sync Data Checkpoint Data Backup Data ConvertTo Data Compare Data ConvertFrom Data Convert Data Compress Data Dismount Data Import Data Initialize Data Limit Data Group Data Edit Data Expand Data Export Data Ping Diagnostic Measure Diagnostic Debug Diagnostic Repair Diagnostic Trace Diagnostic Test Diagnostic Resolve Diagnostic Uninstall Lifecycle Unregister Lifecycle Wait Lifecycle Suspend Lifecycle Disable Lifecycle Deny Lifecycle Install Lifecycle Enable Lifecycle Assert Lifecycle Approve Lifecycle Confirm Lifecycle Complete Lifecycle Start Lifecycle Resume Lifecycle Submit Lifecycle Stop Lifecycle Register Lifecycle Invoke Lifecycle Restart Lifecycle Request Lifecycle Use Other Unblock Security Unprotect Security Grant Security Block Security Protect Security Revoke Security