Resources/Samples/Script.ps1
#requires -version 5 <# .SYNOPSIS <Overview of script> .DESCRIPTION <Brief description of script> .PARAMETER Parameter <Brief description of parameter input required> .PARAMETER Parameter2 <Brief description of parameter2 input required> .INPUTS <Inputs if any, otherwise state None> .OUTPUTS Logs output by default to $env:temp, the users temp folder <Outputs if any, otherwise state None> <example: Log file stored in C:\Windows\Temp\<name>.log> .NOTES Version: 1.0 Author: <Name> Creation Date: <Date> Purpose/Change: Initial script development .EXAMPLE <Example goes here. Repeat this attribute for more than one example> .LINK Any Links with addtional information on the use of the script #> #region Script Parameters [CmdletBinding()] param ( [Parameter(Mandatory=$false,Position=0, HelpMessage = "ParamterMessage")] [string]$Parameter = "first", [Parameter(Mandatory=$false,Position=1, HelpMessage = "Paramter2Message")] [boolean]$Parameter2 = $true ) #endregion Script Parameters begin{ #region Initialisations Set-StrictMode -Version Latest <# Set Action if required to troubleshoot SilentlyContinue 0 Ignore this event and continue Stop 1 Stop the command Continue 2 Handle this event as normal and continue Inquire 3 Ask whether to stop or continue Ignore 4 Ignore the event completely (not even logging it to the target stream) Suspend 5 Reserved for future use. Break 6 Enter the debugger. #> # $ErrorActionPreference = "Continue" #Default Continue # $ProgressPreference = "Continue" #Default Continue # $VerbosePreference = "SilentlyContinue" #Default SilentlyContinue # $DebugPreference = "Continue" #Default SilentlyContinue # $WarningPreference = "Continue" #Default Continue # $InformationPreference = "Continue" #Default SilentlyContinue #endregion Initialisations #region Modules ## Import-Module ActiveDirectory #endregion Modules #region Declarations #Script Version [version]$Script:sScriptVersion = "1.0.0.0" #endregion Declarations Write-Debug -Message "Begin $($MyInvocation.MyCommand.Name) version '$($Script:sScriptVersion)' at '$(Get-Date)'" } process{ Write-Debug -Message "Process $($MyInvocation.MyCommand.Name) at '$(Get-Date)'" try{ Write-Information -Message "Parameters passed: $($Parameter), $($Parameter2)" if($Parameter2){ Write-Warning -Message "Testing a Warning" }else{ Write-Error -Message "Testing a Error" exit } Write-Output "Success $($MyInvocation.MyCommand.Name) at '$(Get-Date)'" } catch{ if ($_.Exception -and $_.Exception.Message) { Write-Error "An error occurred: $($_.Exception.Message)" } else { Write-Error "An error occurred, but no additional information is available." } } finally{ Write-Debug -Message "Finally $($MyInvocation.MyCommand.Name) at '$(Get-Date)'" } } end{ Write-Debug -Message "End $($MyInvocation.MyCommand.Name) at '$(Get-Date)'" } |