March 12 2010

Send SCCM task sequence email report



----------------------------------------------------------------------------
I use a maximum of one Google Ad per post to help offset some of my blog hosting costs.

----------------------------------------------------------------------------

I wanted an easy way to know if OS deployments were failing or succeeding. We’ve come up with a good way of sending an email outlining task sequence completion status.

  • In SCCM, create a Status Filter rule by going to Site Database – Site Management – Primary Site – Site Settings – Status Filter Rules.
  • On the general tab, use Component : Task Sequence Manager, Message ID: 11170 . (11170 signifies failure, 11171 is for success.)
  • On the actions tab, tick Run a program and use something like ‘powershell.exe D:SCRIPTSTS_Email_Notification.PS1 %msgsys’.

TS_Email_Notification.PS1 should contain the following:

param([string]$strComputerName)
$erroractionpreference = "SilentlyContinue"
$strSMTP = "mail.domain.com"
$strSubject = "SCCM OSD Deployment Completed for $strComputerName"
$strBody = "$strComputerName has Completed the Task Sequence"
$MailMessage = New-Object System.Net.Mail.MailMessage
$MailMessage.IsBodyHtml = $true
$SMTPClient = New-Object System.Net.Mail.smtpClient
$SMTPClient.host = $strSMTP
$Sender = New-Object System.Net.Mail.MailAddress("sender@domain.com", "Sender")
$Recipient = New-Object System.Net.Mail.MailAddress("recipient@domain.com", "Recipient")
$MailMessage.Sender = $Sender
$MailMessage.From = $Sender
$MailMessage.Subject = $strSubject
$MailMessage.To.add($Recipient)
$MailMessage.Body = $strBody
$SMTPClient.Send($MailMessage)

You just need to adjust the above Powershell script for your mail settings and you will now receive an email each time there is a successful or failed OS deployment.



----------------------------------------------------------------------------
I use a maximum of one Google Ad per post to help offset some of my blog hosting costs.

----------------------------------------------------------------------------

March 12 2010

Remove computer association from collection after SCCM task sequence

During SCCM OS deployment, you need to add a computer association so you can deploy your OS to a targeted machine. The problem with this is that the computer resource is still left in the collection after deployment. Use this technique to delete the resource once a successful OS deployment is completed:

Copy the below code into a VBS file called remove_from_collection.vbs.

Modify the code so that the sCollectionID = “ABC00013” has the collection ID of your collection from which the resource will be deleted:


On Error Resume Next
Dim oNetwork, oLocator, oSWbemServices, oCollection
Dim sComputerName, sSMSServer, sSMSSiteCode, sCollectionID, RuleSet
Set oNetwork = CreateObject("WScript.NetWork")
'CollectionID from which to remove the comouter
sCollectionID = "ABC00013"
'————————————————————
'Get Command Line arguments
Set args = WScript.Arguments
sComputername = args.Item(0)
If sComputerName = NULL then
wscript.quit
End if
'————————————————————
'Main script
Set swbemLocator = CreateObject("WbemScripting.SWbemLocator")
swbemLocator.Security_.AuthenticationLevel = 6 'Packet Privacy.
Set swbemServices = swbemLocator.ConnectServer(".", "rootSMS")
Set oProviderLocation = swbemServices.InstancesOf("SMS_ProviderLocation")
For Each oLocation In oProviderLocation
If oLocation.ProviderForLocalSite = True Then
Set swbemServices = swbemLocator.ConnectServer(oLocation.Machine, "rootsmssite_" + oLocation.SiteCode)
End If
Next
Set oCollection = SWbemServices.Get("SMS_Collection='" & sCollectionID & "'")
RuleSet = oCollection.CollectionRules
For Each Rule In RuleSet
If Rule.Path_.Class = "SMS_CollectionRuleDirect" Then
If LCase(Trim(Rule.RuleName)) = LCase(Trim(sComputerName)) Then
oCollection.DeleteMembershipRule Rule
End If
End If
Next
WScript.Quit(0)

Create a Status Filter rule by going to Site Database – Site Management – Primary Site – Site Settings – Status Filter Rules.

On the general tab, use Component : Task Sequence Manager, Message ID: 11171 .

On the actions tab, tick Run a program and use something like ‘cscript.exe D:SCRIPTSremove_from_collection.vbs %msgsys’.


This will trigger the script each time a task sequence is reported to the SCCM primary site to be completed successfully and will use the computername (%msgsys) from the status message and remove it from the collection in the script.

Original posting and more discussion here –> http://social.technet.microsoft.com/Forums/en-US/configmgrsdk/thread/9205e49b-9d0e-462e-8998-87e6c31f9c41

Further samples and additional parameter information can be found here http://technet.microsoft.com/en-us/library/bb693758.aspx and http://technet.microsoft.com/en-us/library/cc181183.aspx