Getting email alert when imaging is finished

I wanted to get some details every time a machine was imaged for my own details.  Mostly for asset tracking purposes I set up the below script to run at the end of my task sequence.

$serial = gwmi win32_bios | select-object SerialNumber | Format-Table -HideTableHeaders | Out-String
$serial = $serial.Trim()
$make = gwmi win32_bios | select-object Manufacturer | Format-Table -HideTableHeaders | Out-String
$make = $make.Trim()
$model = gwmi win32_computersystem | select-object model | Format-Table -HideTableHeaders | Out-String
$model = $model.Trim()
$hostname = hostname
$processor = gwmi win32_processor | select-object name | Format-Table -HideTableHeaders | Out-String
$processor = $processor.Trim()
$totalmemory = gwmi Win32_PhysicalMemory | Measure-Object -Property capacity -Sum | Foreach {"{0:N2}" -f ([math]::round(($_.Sum / 1GB),2))}
$operatingsystem = gwmi Win32_OperatingSystem | Select-Object caption, version | Format-Table -HideTableHeaders | Out-String
$operatingsystem = $operatingsystem.Trim()

$EmailFrom = “”

$EmailTo = “”

$Subject = “$hostname has been imaged”

$Body = “PC imaged is $hostname with Serial $serial and Make and Model $make $model. Processor is $processor. Ram is $totalmemory GB. Operating System is $operatingsystem”

$SMTPServer = “ipaddress”

$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 25)

$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)

It is really nice to get all this info.

PC imaged is PCname with Serial R9ZRLB8 and Make and Model LENOVO 23594LU.  Processor is Intel(R) Core(TM) i5-3230M CPU @ 2.60GHz.  Ram is 8.00 GB.  Operating System is Microsoft Windows 10 Pro 10.0.15063

I suppose this could also be modified so that the tech imaging the machine could also get the email.  Maybe basing it off of the machine’s OU.  Hopefully someone finds this useful but I have found it quite handy.  I have also finished a script to gather logs when the task sequence fails and send them to me but I am still testing that out and will save that for my next post.

Update – So just wanted to update that if you wanted to make this easier there is actually a send-mailmessage powershell cmdlet that does the same thing for the send email portion.  Mine still work just fine though 🙂

More info on send-mailmessage below.




Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s