ConfigMgr 2007 and changing the Package Source Directory by script

Sometimes there is a good reason to get out of your comfort zone. One of those reasons is moving the Source Directory of all packages to a different server/ share. This means there has to come a script to change the Source Directory of all packages, as it is not a job that you want to do manually, and scripting is not really my thing… But as it cost me some time to create something nice of it, I will share it so everyone can “enjoy it”.

I created three subroutines, one for connecting to the SMS Provider, one for changing the Package Source Path and one for change the Content Source Path. The Package Source Path counts for all the different types of packages and the Content Source Path only counts for Drivers. The only thing that needs to be adjusted is the old and the new location of the Package Source Directory. This script needs to be run from the Site Server.

Dim objSWbemServices

Set FSO = CreateObject (“Scripting.FileSystemObject”)
Set logFile = FSO.CreateTextFile (“PkgSourcePathLOG.csv”)

sOldServerShare = “<SERVER>\<SHARE>”
sNewServerShare = “<SERVER>\<SHARE>”
 
ConnectToSMSProvider()
ChangePkgSourcePath(“SMS_Package”)
ChangePkgSourcePath(“SMS_SoftwareUpdatesPackage”)
ChangePkgSourcePath(“SMS_ImagePackage”)
ChangePkgSourcePath(“SMS_OperatingSystemInstallPackage”)
ChangePkgSourcePath(“SMS_DriverPackage”)
ChangeContentSourcePath(“SMS_Driver”)

‘==================================
‘ Sub Routine to Connect to the SMS Provider
‘==================================
Sub ConnectToSMSProvider()
   Set objSWbemLocator = CreateObject(“WbemScripting.SWbemLocator”)
   Set objSWbemServices = objSWbemLocator.ConnectServer(“.”, “root\sms”)
   Set ProviderLocation = objSWbemServices.InstancesOf(“SMS_ProviderLocation”)
   For Each Location In ProviderLocation
      If Location.ProviderForLocalSite = True Then
         Set objSWbemServices = objSWbemLocator.ConnectServer(Location.Machine, “root\sms\site_” + Location.SiteCode)
      End If
   Next
End Sub

‘==================================
‘ Sub Routine to Change the Package Source Path
‘==================================
Sub ChangePkgSourcePath(strClass)
   Set colSWbemObjectSet = objSWbemServices.execQuery(“SELECT * FROM ” & strClass)
   For Each objSWbemObject In colSWbemObjectSet
      sOldPkgSourcePath = objSWbemObject.PkgSourcePath
      sNewPkgSourcePath = Replace(sOldPkgSourcePath, sOldServerShare, sNewServerShare)
      logFile.Write “Setting Package Source Path for ” & objSWbemObject.Name & ” from ” & sOldPkgSourcePath & ” to ” & sNewPkgSourcePath
      objSWbemObject.PkgSourcePath = sNewPkgSourcePath
      objSWbemObject.put_
   Next
End Sub

‘==================================
‘Sub Routine to Change the ContentSource of Drivers
‘==================================
Sub ChangeContentSourcePath(strClass)
   Set colSWbemObjectSet = objSWbemServices.execQuery(“SELECT * FROM ” & strClass)
   For Each objSWbemObject In colSWbemObjectSet
      sOldPathString = objSWbemObject.ContentSourcePath
      sNewPathString = Replace(sOldPathString, sOldServerShare, sNewServerShare)
      logFile.Write “Setting Content Source Path for ” & objSWbemObject.LocalizedDisplayName & ” from ” & sOldPathString & ” to ” & sNewPathString
      objSWbemObject.ContentSourcePath = sNewPathString
      objSWbemObject.put_
   Next
End Sub

Keep attention to the fact that changing the Source Directory will make the Distribution Point re-process the packages. This is the part that virtual application packages don’t like. They will generate lots of errors in the distrmgr.log and to fix it I had to touch them all and re-select the XML –file from the original project directory.

8 thoughts on “ConfigMgr 2007 and changing the Package Source Directory by script”

  1. Pieter,

    Tried this in a test environment but it does not seem to work. All my driver path are empty afterwards. It also shows in the log files:
    “Setting Content Source Path for XXX from \\MYSERVER\E$\V7.7.0.406_32bit\Driver to ”
    As you can see the last part is empty.

    As for Driver packages it does not change any path, The stay the same ;( The log files also shows no new unc paths. Will send you the logs if needed.

    Regards, Ton

    Reply
    • Hi Ton,

      I almost don’t dare to say this, but there was a “copy and paste error” in the driver-part of the script…
      It said sOldPkgSourcePath while it should be sOldPathString
      Sorry!!!

      Peter

      Reply
  2. Peter,

    Ok, tx. That will solve the single driver issue. Will let u know if its working soon.
    What about my Driver Packages problem (only old path is set and used) You did not change that?

    Rgrds,

    Ton

    Reply
  3. I’m getting the error:

    VBScript runtime error: Type mismatch: ‘ChangePkgSourcePath’

    Ever seen this with this script?

    Reply
  4. Hi Peter,
    I know this is a bit old at this point, but I came across your site while looking for a method to change the source directory for my packages (imagine that!)…in either case, at a glance I noticed the vars sOldServerShare and sNewServerShare…currently our package source files are all pointed to the local disk and not a file share (I know, I know), and I was wondering if this script will change the source location from the local drive to a specified file share, or just change from one file share to another?

    caleb

    Reply
    • Hi Caleb,
      Sorry for the late reply, I was on vacation…
      What this script actually does, is changing string1 (sOldServerShare) in to string2 (sNewServerShare). So it doesn’t matter if string1 is a local or networkdrive.
      Peter

      Reply

Leave a Reply to Caleb Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.