Configmgr2007 : Change your packages source path after SCCM site migration with a script

August 17, 2010 at 6:39 am in AdminUi, ConfigMgr, ConfigMgr 2007, ConfigMgr 2007 R2, ConfigMgr SP2, configmgr2007, ConfigMgr2007 R3, Installation, migration, sccm, SCCM 2007, SCCM 2007 R2, SCCM 2007 R3, SCCM 2007 SP2, sccm2007, script, SMS, Sms 2003 by Kenny Buntinx [MVP]

A few days ago , I explained in this blogpost “http://scug.be/blogs/sccm/archive/2010/08/10/configmgr-connecting-primary-child-sites-to-central-primary-parent-site-in-and-out-of-same-domain.aspx“ on how I was busy migrating one SCCM 2007 Primary site to another , because we wanted to start with a complete new environment (w2k8 x64) .As there is no supported direct upgrade path, I built an entire new SCCM server with SP2 -R2.I made it a child site of the existing SCCM primary site and let all the packages replicate.

After I solved a problem with locked padlocks on my packages in this blogpost :”http://scug.be/blogs/sccm/archive/2010/08/11/configmgr-locked-packages-after-sccm-site-migration-and-how-to-solve-it.aspx”, I needed to make sure that I would change all my old packages source paths ( a.e \\SCCM01\G$\src\<package folder> into my new package source paths (a.e \\Fileserver1\SCCMSRC\<package folder> that was residing on a DFS share .

To do that I needed a script , as doing +- 100 packages was a little to much work for a lazy admin :-)

I thought I had a great script from the site of Brian S. Tucker , as I used it already multiple times. It turned out that it was useless in this project as I needed to change not only the server name , but the complete path.

Script 1 : If you only need to change the server name in the package source path. Otherwise use my script “script 2” in the section under “script 1” below .

Copy code below this line—————————————————

Dim oWbemServices
If UCase(Right(Wscript.FullName, 11)) = "WSCRIPT.EXE" Then
    Wscript.Echo "This script must be run under CScript."
    Wscript.Quit
End If
If WScript.Arguments.Count <> 1 Then
    WScript.Echo "Wrong number of arguments were passed."
    WScript.Quit
End If
CONNSCCM()

For Each oPackage In oWbemServices.execquery("select * from sms_package")
  sOldPathString = oPackage.pkgsourcepath
  If InStr(sOldPathString,"\\") Then
                iStart = InStr(3,sOldPathString,"\")
                sNewPathString = Right(sOldPathString,(LEN(sOldPathString)-iStart))
                sNewPathString = "\\" & WScript.Arguments(0) & "\" & sNewPathString
                WScript.Echo "Setting Package Path for " & oPackage.Name & " from " & sOldPathString & " to " &  sNewPathString
                oPackage.pkgsourcepath = sNewPathString
                oPackage.put_
  End If
Next

WScript.Echo "Done"

Sub CONNSCCM()
  Set oWbemLocator = CreateObject("WbemScripting.SWbemLocator")
  Set oWbemServices = oWbemLocator.ConnectServer(".", "root\sms")
  Set oSCCMProvLoc = oWbemServices.InstancesOf("SMS_ProviderLocation")

  For Each oLoc In oSCCMProvLoc
        If oLoc.ProviderForLocalSite = True Then
            Set oWbemServices = oWbemLocator.ConnectServer(oLoc.Machine, "root\sms\site_" + oLoc.SiteCode)
        End If
  Next
End Sub

Copy code above this line—————————————————

Thanks to my fellow Belgium MVP ”Kim Oppalfens” , I was able to alter the above script to my needs and change the complete source path , except for the package source folder .

Script 2 : If you need to change the complete package source path , except the package folder name.

Copy code below this line—————————————————

on error resume next
Dim oWbemServices
Set fs = CreateObject ("Scripting.FileSystemObject")
Set logFile = fs.CreateTextFile ("pkg_log.csv")
CONNSCCM()

For Each oPackage In oWbemServices.execquery("select * from sms_package")
  sOldPathString = oPackage.pkgsourcepath
  If InStr(sOldPathString,"\\") Then 
  arrsrcPath = Split( soldPathString, "\")
  snewpathString = "\\Fileserver1\sccmsrc\" & arrsrcPath(Ubound(ArrSrcPath)-0)

                logFile.Write "Setting Package Path for " & oPackage.Name & " from " & sOldPathString & " to " &  sNewPathString
                logFile.WriteLine ""
                oPackage.pkgsourcepath = sNewPathString
                oPackage.put_
  End If
Next

WScript.Echo "Done"

Sub CONNSCCM()
  Set oWbemLocator = CreateObject("WbemScripting.SWbemLocator")
  Set oWbemServices = oWbemLocator.ConnectServer(".", "root\sms")
  Set oSCCMProvLoc = oWbemServices.InstancesOf("SMS_ProviderLocation")

  For Each oLoc In oSCCMProvLoc
        If oLoc.ProviderForLocalSite = True Then
            Set oWbemServices = oWbemLocator.ConnectServer(oLoc.Machine, "root\sms\site_" + oLoc.SiteCode)
        End If
  Next
End Sub

 

Copy code above this line—————————————————

 

Hope it helps ,

 

Kenny Buntinx

Tweet about this on TwitterShare on FacebookShare on Google+Share on LinkedInPin on Pinterest