Running Actions Based on #ConfigMgr Status Filter Rules with #PowerShell

Here is an example of running a custom action when an Application is deployed (based on status filter rule).

Save this script as “C:\Scripts\StatusFilter\NoSecretDeployments.ps1”

#status filter variables: http://technet.microsoft.com/en-us/library/bb693758.aspx
#New Deployment of Application
#Source: SMS Provider
#Message ID: 30226
#Run Command (combine the next three lines, replace the # with a space:
#C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
#-command "& {c:\scripts\statusfilter\nosecretdeployments.ps1
#-computername '%msgsys' -msgdesc '%msgdesc'}"

[CmdletBinding()]
Param(
  [Parameter(Mandatory=$True)]
   [string]$ComputerName,

  [Parameter(Mandatory=$True)]
   [string]$MSGDesc,

   [Parameter()]
   [string]$AdditionalInfo
)

function write-log ($string)
{
    $string + " " + (get-date) `
    | Out-File C:\scripts\StatusFilter\NoSecretDeployments.log -Append
}

write-log ("Source " + $ComputerName)
write-log ($MSGDesc)

Now create a new application, and observe NoSecretDeployments.log in c:\scripts\statusfilter. You can also debug the execution by reviewing statmgr.log:

NewDeploymentOfApps_SFR_3

In this example, you see how we can easily write the information to a log file. You can take this basic example, and leverage the Send-MailMessage cmdlet so that the script automatically notifies a distribution list each time an application deployment is created.

Learn more about Status Filter Rules: http://technet.microsoft.com/en-us/library/cc181208.aspx

Learn more about command-line parameters for Status Filter Rules: http://technet.microsoft.com/en-us/library/bb693758.aspx

 

Happy Scripting!

 

Greg

 

About Greg Ramsey
Greg Ramsey is a systems engineer specializing in global systems management for Dell IT. He has a B.S. in Computer Sciences and Engineering from the Ohio State University and is a Microsoft Most Valuable Professional (MVP) for Microsoft System Center Configuration Manager. Greg coauthored SMS 2003 Recipes: A Problem-Solution Approach (Apress, 2006), Microsoft System Center Configuration Manager Unleashed (Sams, 2009), Microsoft System Center 2012 Configuration Manager Unleashed (Sams, 2012), and Microsoft System Center 2012 Configuration Manager: Administration Cookbook (Packt Publishing, 2012), and Microsoft System Center 2012 Configuration Manager R2 Unleashed (Sams, 2012). Greg is cofounder of the Ohio SMS Users Group, and the Central Texas Systems Management User Group.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: