Skip to content

Instantly share code, notes, and snippets.

@jouleSoft
Forked from 9to5IT/Script_Template.ps1
Last active March 8, 2021 13:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jouleSoft/b10ede4ff3ef47122f9041a3f205c245 to your computer and use it in GitHub Desktop.
Save jouleSoft/b10ede4ff3ef47122f9041a3f205c245 to your computer and use it in GitHub Desktop.
PowerShell: Script Template
#requires -version 2
<#
.SYNOPSIS
<Overview of script>
.DESCRIPTION
<Brief description of script>
.PARAMETER <Parameter_Name>
<Brief description of parameter input required. Repeat this attribute if required>
.INPUTS
<Inputs if any, otherwise state None>
.OUTPUTS
<Outputs if any, otherwise state None - example: Log file stored in C:\Windows\Temp\<name>.log>
.NOTES
GitHub repo: https://github.com/<user>/<repo>
License: <license>
PS Edition: <Core> | <Desktop>
--
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>
#>
#---------------------------------------------------------[Initializations]--------------------------------------------------------
#Set Error Action to Silently Continue
$ErrorActionPreference = "SilentlyContinue"
#Dot Source required Function Libraries
. "C:\Scripts\Functions\Logging_Functions.ps1"
#----------------------------------------------------------[Declarations]----------------------------------------------------------
#Script title, version, description and license
$sScriptTitle = "<script_name>.ps1"
$sScriptVersion = "1.0"
$sScriptDescription = "<Short description>"
$sScriptLicense = "<license>"
#Log File Info
$sLogPath = "C:\Windows\Temp"
$sLogName = "<script_name>.log"
$sLogFile = Join-Path -Path $sLogPath -ChildPath $sLogName
#-----------------------------------------------------------[Functions]------------------------------------------------------------
<#
Function <FunctionName>{
Param()
Begin{
Log-Write -LogPath $sLogFile -LineValue "<description of what is going on>..."
}
Process{
Try{
<code goes here>
}
Catch{
Log-Error -LogPath $sLogFile -ErrorDesc $_.Exception -ExitGracefully $True
Break
}
}
End{
If($?){
Log-Write -LogPath $sLogFile -LineValue "Completed Successfully."
Log-Write -LogPath $sLogFile -LineValue " "
}
}
}
#>
function Get-ScriptHeader {
<#
.SYNOPSIS
Print header lines
.DESCRIPTION
For script use. Print the first script lines indicating title, version, description and license.
.PARAMETER Title
Mandatory. Script title.
.PARAMETER Version
Mandatory. Script version
.PARAMETER Description
Mandatory. Script description
.PARAMETER Version
Mandatory. Script license. Set to $Null for no license.
.INPUTS
Paramaters above
.OUTPUTS
String
.NOTES
Version: 1.0
Author: Julio Jimenez Delgado
Creation Date: 14/05/2020
Change: Initial function development
#>
[CmdletBinding()]
Param(
[Parameter(Mandatory=$True, Position=0)]
[String]$Title,
[Parameter(Mandatory=$True, Position=1)]
[String]$Version,
[Parameter(Mandatory=$True, Position=2)]
[String]$Description,
[Parameter(Mandatory=$False, Position=3)]
[String]$License
)
Process{
Write-Host "$Title v." -ForegroundColor Gray -noNewLine
Write-Host $Version -ForegroundColor Yellow -noNewLine
Write-Host " - $Description" -ForegroundColor Gray -NoNewline
if($License -ne $Null){
Write-Host " ($License)" -ForegroundColor Gray
}
}
}
#-----------------------------------------------------------[Execution]------------------------------------------------------------
#Show script header
Get-ScriptHeader -Title $sScriptTitle -Version $sScriptVersion -Description $sScriptDescription -License $sScriptLicense
#Operations
#Log-Start -LogPath $sLogPath -LogName $sLogName -ScriptVersion $sScriptVersion
#Script Execution goes here
#Log-Finish -LogPath $sLogFile
#----------------------------------------------------------[Finalization]-----------------------------------------------------------
Remove-Variable sScriptTitle
Remove-Variable sScriptVersion
Remove-Variable sScriptDescription
Remove-Variable sScriptLicense
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment