Tuesday, September 16, 2008

Scripting SCCM to refresh a package source directory

My company has a need to have a particular package's distribution points update automatically when a file in the package source directory changes. We looked at the package's built in option to automatically update DP's on a schedule. Ultimately, we decided this would not work. We have a very short window to obtain a 4GB updated package source and then distribute that content to clients. If we set the window too small (every 20 minutes), then clients would be mostly locked out from getting content from the DP, since the DP would be constantly updating. If we set it too large, we don't get the content within the targeted time window. Using the SCCM SDK ( http://www.microsoft.com/downloads/details.aspx?FamilyId=064A995F-EF13-4200-81AD-E3AF6218EDCC&displaylang=en ) and information from a post by aparrott on myitforum: http://www.myitforum.com/forums/m_180582/mpage_1/key_/tm.htm#180582 we were able to create our own script that will detect the change and then update the DP. I have a scheduled task that runs every 20 minutes. If the last modified stamp on the text file is different, then the DP's will update. This happens once a day, but I get new content onto the DP's within 25 minutes. Now I just need to delete the old mandatory assignment and create a new one.

Careful of the wordwrap!  I suggest you copy and paste into notepad.
' VBScript Source File -- Created with PrimalScript.
' NAME: SCCM_Refresh_DP_Nightly_Build.vbs
' Created by: Bill Phillips, ESRI
' Date: 09/15/2008
' Run this as a scheduled task under the System account.
' Machine's account must have rights to the shares.
' Example code from: http://www.myitforum.com/forums/m_180582/mpage_1/key_/tm.htm#180582

On Error Resume Next

' --- Set Variables
siteName = "tst"
serverName = "SMSSERVER"
SMS_PackageID = "tst00158"

' --- Create Objects
Set loc = CreateObject("WbemScripting.SWbemLocator")
Set WbemServices = loc.ConnectServer(servername , "root\SMS\site_" & siteName)
set FSO=CreateObject("Scripting.FileSystemObject")


' --- Compare Files
Function CompareFiles()
Set objSourceBuildNumTextDate = FSO.GetFile ("\\smsserver\source\foo.txt")
Set objDestBuildNumTextDate = FSO.GetFile ("\\dpserver\SMSPKGE$\tst00158\foo.txt")
If not objSourceBuildNumTextDate.DateLastModified = objDestBuildNumTextDate.DateLastModified Then RefreshPKG
End Function

' --- Refresh Package
Function RefreshPKG()
Set packages = WbemServices.ExecQuery("Select * From SMS_Package where PackageID = '" & SMS_PackageID & "'")
For Each package In packages

Package.RefreshPkgSource( )


End Function

No comments: