-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSccm.OsBuild.StartEmail.ps1
108 lines (81 loc) · 3.35 KB
/
Sccm.OsBuild.StartEmail.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
$ErrorActionPreference = 'stop'
Set-PSDebug -Strict
$PSScriptDirectory = (Split-Path $MyInvocation.MyCommand.Path -Parent).ToLower()
Import-Module ($PSScriptDirectory + '\Sccm.OsBuild.Logic.psm1') -Verbose
$_settingsFileJson = Get-Content ($PSScriptDirectory + '\Sccm.OsBuild.Scripts.Settings.json') -Raw | ConvertFrom-Json
$_smtpServer = $_settingsFileJson.Generic_Settings.SMTP_Server
$_cssStle = $_settingsFileJson.Generic_Settings.CSS_Style
$_emailTo = $_settingsFileJson.Generic_Settings.Email_To
$_sccmOsdReportURL = $_settingsFileJson.Sccm_OsBuild_StartEmail.SCCMOsdReportURL
function Send-CustomMailMessage($smtpFrom, $displayName, $subject, $body, $smtpTo, $attachments = $null, $html = $true)
{
<#
.Synopsis
Sends emails by relay
.Description
Can be used to send emails as someone else
.Example
Send-CustomMailMessage $_mailErrorTo 'belal, abu' 'relayed emailed' 'body of email' '[email protected]'
.Notes
AUTHOR: Abu Belal
LASTEDIT: 06-June-2013
EDITS: Removed logging info
Removed try catch around send mail, callee should handle this
#>
$developer = "[email protected]"
$from = New-Object System.Net.Mail.MailAddress($smtpFrom, $displayName)
$mail = New-Object System.Net.Mail.MailMessage
$smtp = New-Object Net.Mail.SmtpClient($_smtpServer)
$mail.From = $from
$mail.To.Add($smtpTo)
#$mail.BCC.Add($_mailErrorToCc)
$mail.Subject = $subject
$mail.Body = $body
$mail.IsBodyHtml = $html
if ($attachments -ne $null)
{
foreach ($attachement in $attachments)
{
$mail.Attachments.Add($attachement)
}
}
$smtp.Send($mail)
}
function Add-EmailTableData($property, $value)
{
[Void] $_emailLog.Append('<tr>')
[Void] $_emailLog.AppendLine()
[Void] $_emailLog.Append('<td>' + $property + '</td>')
[Void] $_emailLog.AppendLine()
[Void] $_emailLog.Append('<td>' + $value + '</td>')
[Void] $_emailLog.AppendLine()
[Void] $_emailLog.Append('</tr>')
[Void] $_emailLog.AppendLine()
}
$_systemDetails = Get-CustomSystemDetails
$_emailLog = New-Object System.Text.StringBuilder
[Void] $_emailLog.Append('<html><head>' + $_cssStle + '</head><body>')
[Void] $_emailLog.Append('<h2 align="center">Build Status</h2>')
[Void] $_emailLog.Append('View realtime build report by clicking <a href="' + $_sccmOsdReportURL + $_systemDetails.mac + '">here </a>')
[Void] $_emailLog.Append('<br><br>')
[Void] $_emailLog.Append('<table id=#buildresult cellspacing="0" border="0">')
[Void] $_emailLog.AppendLine()
[Void] $_emailLog.Append('<tr>')
[Void] $_emailLog.AppendLine()
[Void] $_emailLog.Append('<td>Property</td>')
[Void] $_emailLog.AppendLine()
[Void] $_emailLog.Append('<td>Value</td>')
[Void] $_emailLog.Append('</tr>')
[Void] $_emailLog.AppendLine()
$_mdtComputerSettings = Get-SccmComputerSettings -macAddress $_systemDetails.Item('mac')
foreach ($property in $_mdtComputerSettings.Table.Columns)
{
if (($_mdtComputerSettings[$property.ColumnName]) -ne [System.DBNull]::Value)
{
Write-Host $property.ColumnName $_mdtComputerSettings[$property.ColumnName]
Add-EmailTableData $property.ColumnName $_mdtComputerSettings[$property.ColumnName]
}
}
[Void] $_emailLog.Append('</table>')
[Void] $_emailLog.AppendLine()
Send-CustomMailMessage ('Sccm.OsBuild.StartEmail@' + $_mdtComputerSettings['OSDComputerName']) 'Sccm.OsBuild.StartEmail' ('Build started on ' + $_mdtComputerSettings['OSDComputerName']) $_emailLog $_emailTo