Categories
ConfigMgr

ConfigMgr : Task Sequence Email Notification and Unknown Computers (MININT names)

I recently had a requirement to facilitate email notifications of Task Sequence Successes and Failures using Site Status Filters. This process is fairly straight forwards however there is one caveat with all of the guides I found online – if you’re using Unknown Computer support all of the email notifications will use the _SMSTSMachineName Task Sequence variable, which will be set to MININT-<XXXXXX> – this rendered this reporting method effectively useless within the environment I was looking to implement this solution within. However I found a solution/workaround for this issue…

Solution Summary

During the Task Sequence:

  1. Map a network folder on the Site Server; I created a Mapping$ share and dedicated service account to write data to this share.
  2. Create a “name mapping” comma-separated text file that contains the _SMSTSMachineName and desired name which is populated in the OSDComputerName Task Sequence variable. This file is always named <_SMSTSMachineName>.txt
  3. Using the Status Filter execute a PowerShell Script that checks for the name mapping file and, if found, emails the success or failure message based upon the desired name. If not found then the email will contain the value of _SMSTSMachineName.

Detailed implementation steps are below.

 

Implementation

Map a network folder on the Site Server

Create a new share on your Primary Site Server, I named the share Mapping$.

Mapping a network drive during a Task Sequence is simply a case of adding a new pre-defined step to the Task Sequence. You’ll find this option under: Add | General | Connect to Network Folder. You can specify the connection credentials as required – I used a dedicated service account. I mapped the folder as Z:

 

Creating the “name mapping” comma-separated text file

Next create a new package that contains the following script, named NameMapping.vbs – be sure to check the drive letter matches the Map network Folder stage from your Task Sequence:

{code lang:text showtitle:false lines:false hidden:false}Const ForReading = 1
Const ForWriting = 2

Dim env, logFile

Set env = CreateObject(“Microsoft.SMS.TSEnvironment”)
Set objFSO=CreateObject(“Scripting.FileSystemObject”)
Set oShell = CreateObject( “WScript.Shell” )

logFile = “Z:\Win7\” & env(“_SMSTSMachineName”) & “.txt”

If NOT(objFSO.FileExists(logFile)) Then
set objFile = objFSO.CreateTextFile(logFile)
Else
set objFile = objFSO.OpenTextFile(logFile,ForWriting)
End If

objFile.WriteLine env(“_SMSTSMachineName”) & “,” & env(“OSDComputerName”)
objFile.Close{/code}

Distribute this package and then add a new Run Command Line step to your Task Sequence that uses this package, running the command: cscript.exe NameMapping.vbs

 

Using the Status Filter execute a PowerShell Script

Next, you’ll need create the following scripts, I stored this under C:\Scripts\ConfigMgr on the Primary Site Server. Be sure that the File Server FQDN matches the loctaion of the Mapping$ share and that you update the SMP server locatons / email addresses.

Now create your Status Filter monitor under Administration | Site Configuration | Sites. Select your Primary Site and from the ribbon menu select Status Filter Rules.

Create a new rule with the following settings:

General

  • Source: Client
  • Site Code: <Primary Site Code>
  • Message ID: 11171
  • Property: Package ID
  • Property value: Package ID of Bare-Metal Task Sequence

Actions

  • Run a Program: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -executionpolicy bypass -file C:\Scripts\ConfigMgr\BareMetal_Success.ps1 -strComputerName %msgsys

You’re good to go – test the Task Sequence to check you get the success message.

For failure notifications create a Status Filter as above with the following differences:

General

  • Source: Client
  • Site Code: <Primary Site Code>
  • Message ID: 11170
  • Property: Package ID
  • Property value: Package ID of Bare-Metal Task Sequence

Actions

  • Run a Program: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -executionpolicy bypass -file C:\Scripts\ConfigMgr\BareMetal_Failure.ps1 -strComputerName %msgsys

 

 

 

 

 

 

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *