Skip to content

Instantly share code, notes, and snippets.

Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@Fysi
Fysi / SQLResultstoEmailSlack.ps1
Last active October 3, 2020 09:38
Powershell script to run a SQL query and if there are results, send an email with csv attachment & post slack message. If no results, send email saying no results.
#Import the PSSlack module
Import-Module PSSlack
#Set user credentials
$User = "$env:UserDomain\$env:UserName"
$PasswordFile = ".\Password.txt"
$KeyFile = ".\AES.key"
$key = Get-Content $KeyFile
$MyCredential = New-Object -TypeName System.Management.Automation.PSCredential `
-ArgumentList $User, (Get-Content $PasswordFile | ConvertTo-SecureString -Key $key)