Resources/Samples/Function-Moderate.ps1
|
function Verb-Noun { <# .SYNOPSIS Brief summary of what this function does. .DESCRIPTION Detailed description of the function's purpose and behavior. .PARAMETER Parameter Description of the first parameter. .PARAMETER Action The action to perform. Valid values are Create, Delete, or List. .EXAMPLE Verb-Noun -Parameter "Value" -Action Create Description of what this example does. .NOTES Version: 1.0 Author: Your Name Creation Date: $(Get-Date -Format 'yyyy-MM-dd') Purpose/Change: Initial function development #> param( [Parameter(Mandatory = $true, Position = 0)] [ValidateNotNullOrEmpty()] [string]$Parameter, [Parameter(Mandatory = $false)] [ValidateSet("Create", "Delete", "List")] [string]$Action = "List" ) try { Write-Verbose "Starting $($MyInvocation.MyCommand.Name) with Parameter: $Parameter, Action: $Action" # Main function logic switch ($Action) { "Create" { Write-Output "Creating item: $Parameter" # Add creation logic here } "Delete" { Write-Output "Deleting item: $Parameter" # Add deletion logic here } "List" { Write-Output "Listing item: $Parameter" # Add listing logic here } } Write-Verbose "Function completed successfully" } catch { Write-Error "An error occurred in $($MyInvocation.MyCommand.Name): $($_.Exception.Message)" throw } } |