Skip to content

Instantly share code, notes, and snippets.

View tobyqin's full-sized avatar
☁️
Enter the cloud.

Toby Qin tobyqin

☁️
Enter the cloud.
View GitHub Profile
## To read the config file with same name as script file in same folder
function Read-ConfigFile($scriptItem)
{
$configFile = $scriptItem.BaseName + ".xml"
$configFilePath = Join-Path $scriptItem.Directory $configFile
Log-Info "Config: $configFilePath"
Get-Content $configFilePath
}
function Execute-command($commandPath)
{
Set-Location $env:TEMP
Log-Info "Command: $commandPath" $logFile
cmd /c "$commandPath"
}
## Initialization
$script_info = Get-Item $MyInvocation.MyCommand.Definition
$script_dir =$script_info.Directory
. "$script_dir\GlobalFunctions.ps1"
$DebugPreference = "Continue"
$ErrorActionPreference = "Stop"
@tobyqin
tobyqin / Trap-Catch.ps1
Created November 12, 2015 07:26
PowerShell trap to get error info
$ErrorActionPreference="Stop"
$DebugPreference="Continue"
trap
{
Write-Debug "=== Enter trap ==="
$funcName = (Get-PSCallStack)[1].Position.Text
$detail = $_ | Out-String
@tobyqin
tobyqin / Send-Email.ps1
Created November 12, 2015 07:24
PowerShell to send email
function Send-Email($to, $cc, $subject, $body)
{
$From = "you@domain.com"
$SmtpHost = "smtp.domain.com"
Send-MailMessage -From $From -Subject $subject -To $to -Cc $cc -Body $body -BodyAsHtml -SmtpServer $SmtpHost
}
$To = "user1@domain.com", "user2@domain.com"
$Cc="boss@domain.com"
$Subject = "Don't worry, it is a test."