Created
October 5, 2019 05:49
-
-
Save ChendrayanV/af2f3bc603df0e50f316e7684401f15c to your computer and use it in GitHub Desktop.
Trigger HTML Email using Azure Functions (PSHTML - PowerShell)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*Every 45 Minutes*/ | |
{ | |
"bindings": [ | |
{ | |
"name": "Timer", | |
"type": "timerTrigger", | |
"direction": "in", | |
"schedule": "0 */45 * * * *" | |
} | |
] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param($Timer) | |
$ADMIN = ([System.Environment]::GetEnvironmentVariable('ADMIN')) | |
# KEY VAULT INTEGRATION | |
$SECRET = ([System.Environment]::GetEnvironmentVariable('SECRET') | ConvertTo-SecureString -AsPlainText -Force) | |
$CREDENTIAL = [pscredential]::new($ADMIN, $SECRET) | |
$MAILBODY = html -Content { | |
head -Content { | |
Title -Content "Azure Resource Report" | |
} | |
#region HTML STYLE | |
style -Content { | |
'#computers { | |
font-family: "Trebuchet MS", Arial, Helvetica, sans-serif; | |
border-collapse: collapse; | |
width: 100%; | |
} | |
#computers td, #computers th { | |
border: 1px solid #ddd; | |
padding: 8px; | |
} | |
#computers tr:nth-child(even) { | |
background-color: #f2f2f2; | |
} | |
#computers tr:hover { | |
background-color: #ddd; | |
} | |
#computers th { | |
padding-top: 12px; | |
padding-bottom: 12px; | |
text-align: left; | |
background-color: #4CAF50; | |
color: white; | |
}' | |
} | |
#endregion | |
body -Content { | |
hr | |
h3 -Content "Azure Resource Information" -Style 'text-align:center' | |
hr | |
table -Id 'computers' -Content { | |
Thead -Content { | |
tr -Content { | |
th -Content "Computer Name" | |
th -Content "Operating System" | |
th -Content "Power State" | |
} | |
} | |
Tbody -Content { | |
$computers = Get-Content .\database\computers.json | ConvertFrom-Json | |
$computers.computers | . { | |
process { | |
tr -Content { | |
td -Content $_.Name | |
td -Content $_.OSType | |
td -Content $_.Status | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
$MAILPARAMS = @{ | |
FROM = $ADMIN | |
# REPLACE TO VALUE WITH YOUR EMAIL ADDRESS | |
TO = 'YOUR EMAIL' | |
SUBJECT = "Azure Resource Information" | |
BODY = $MAILBODY | |
BODYASHTML = $true | |
SMTPSERVER = 'smtp.office365.com' | |
Usessl = $true | |
CREDENTIAL = $CREDENTIAL | |
} | |
Send-MailMessage @MAILPARAMS |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment