# Desc: PowerShell template
# Auth: Brian Dill 2021-01-26
# License: Shoutout-ware. If you find this script useful give me a shout out on Twitter @bdill
# URL: https://pastebin.com/2srZrGqX
# Other useful stuff: https://pastebin.com/u/bdill
# Upd: 2022-05-04 bdill
Clear-Host
$Script:error.clear()
#-------------------------------------------------------------------------------
# CONFIG PARAMS
#-------------------------------------------------------------------------------
$Server = "Server01"
$Database = "MyDatabase"
$ScriptName = "My_script.ps1"
$LocalPath = "D:\tmp\"
$RemotePath = "\\MyServer\MyShare\MyFolder"
$SessionLogContainer = "" #Holding tank for all session LogLine data
$CurDate = Get-Date -Format yyyy-MM-dd_hh.mm.ss
$StartTime = Get-Date
$sbExec = [System.Text.StringBuilder]::New()
#-------------------------------------------------------------------------------
# Functions
#-------------------------------------------------------------------------------
function LogLine {
param ([string]$s )
$d2 = Get-Date -format "yyyy-MM-dd HH:mm:ss";
$s = "$d2 - $s";
Write-Host "$s";
Echo "$s" | Out-File $LogFile -append;
$script:SessionLogContainer += $s + "`n"
}
#-------------------------------------------------------------------------------
# INLINE CODE
#-------------------------------------------------------------------------------
# inline code here
#-------------------------------------------------------------------------------
# Email results
$smtp = "mail.MyCompany.com"
$from = "Server01 <[email protected]>"
$to = "[email protected]"
$subject = "[PSOps]: SUCCESS - $ScriptName completed $CurDate"
If ($Script:error) {
Logline "The following error(s) were received:"
Logline $Script:error
#$Script:error | Out-File $LogFile -append
$subject = "[PSOps]: ERROR - $ScriptName failed $CurDate"
}
#send-MailMessage -SmtpServer $smtp -From $from -To $to -Subject $subject -Body "$SessionLogContainer"
Comments