SCCM: Migrating to a new source code server

I have run across this several time in the past where the source code location for your packages (and now drivers as well) needs to be moved to a new server. I have 3 scripts I use (Could be combined into one if you like) that will allow you to change the location for each object.

Script 1: remapPkgs.vbs
This script will modify the source path for all (non Driver related) packages.

Script 2: remapDrivers.vbs
This script will remap all the source locations for the drivers that have been imported.

Script 3: remapDriverPkgs.vbs
This script will remap all the source locations for your driver packages.

VERY IMPORTANT – When you run the remapPkgs.vbs and the remapDriverPkgs.vbs it will trigger a Distribution Point update for all your packages. You will likely want to run this after hours or over the weekend depending on how many packages you have and what your bandwidth is to your DP’s.

*UPDATE* – Couple of things I noticed in my environment after running these scripts.
1. We use Nomad Branch from 1E. This adds a tab to your packages where you specify if you want to enable Nomad. After running the scripts I had to go back and reset this on all my packages.
2. Much more importantly we also discovered that these scripts re-enabled the setting for all of our App-V packages to “remove when no longer advertised”. Under normal day to day operations this setting is desired for us however as part of our re-assigning the clients to a new site code all local policy is deleted and re-downloaded from the new server. Well with that option still enabled it would remove all App-V apps from all machines as the policy would get deleted and it would not come back automatically. This is why we removed that option. Long story short we had to go back and remove the option again from all App-V packages after migrating the source code.

Another important note regarding App-V packages:
Although Microsoft does not give you the option to modify the source directory of your Virtual Applications via the Admin Console the script above will remap your App-V packages as well. In my environment however I was required to touch each Virtual App after the script and “re-import” the package if you will. This was achieved by clicking the Properties of the Virtual App, Click Data Source, then click “Set”. In the “Virtual Application package source directory” click “Browse” and specify the original location of the xml file used to create the package. I found that in most circumstances I needed to delete the contents of the “ConfigMgr data source directory” prior to browsing to the xml file. Once you import the package again the contents of the source directory get re-created and the package resent to the DP’s.

The syntax for the scripts are included in the script header however its pretty simple (must be run from the SCCM server itself):

cscript scriptname.vbs NEWSERVERNAME

So example: My current source path that I want to change is:
\\SERVER01\SOURCE$\SoftwareInstalls\Adobe_AcrobatReader_9.0_R01

I would run the script like so:
cscript remapPkgs.vbs SERVER02

This will change the source directory to:
\\SERVER02\SOURCE$\SoftwareInstalls\Adobe_AcrobatReader_9.0_R01
(And trigger an update to the DP)

Again these scripts are setup to do all packages in one fell swoop and designed to only need to replace the server name. You could easily modify the scripts to change the share name, etc as needed.

I would also recommend commenting out the “put_” statement and run the script to verify it works prior to actually making the changes.
_________________________________________________
Script 1 (Mind word wrapping)
'///////////////////////////////////////////////////
'
' SYNTAX: cscript remapPkgs.vbs NEWSERVERNAME
'
'///////////////////////////////////////////////////////////
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
'====================================================
'== Execute SUB to connect to SCCM Provider
'====================================================
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: Connects to the SMS Provider
'====================================================
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

Script 2 (Mind word wrapping)
'///////////////////////////////////////////////////
'
' SYNTAX: cscript remapDrivers.vbs NEWSERVERNAME
'
'///////////////////////////////////////////////////////////
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
'====================================================
'== Execute SUB to connect to SCCM Provider
'====================================================
CONNSCCM()
For Each oPackage In oWbemServices.execquery("select * from sms_Driver")
sOldPathString = oPackage.contentsourcepath
If InStr(sOldPathString,"Latitude 13") Then
iStart = InStr(3,sOldPathString,"\")
sNewPathString = Right(sOldPathString,(LEN(sOldPathString)-iStart))
sNewPathString = "\\" & WScript.Arguments(0) & "\" & sNewPathString
WScript.Echo "Setting Package Path for " & oPackage.LocalizedDisplayName & " from " & sOldPathString & " to " & sNewPathString
'WScript.Echo sOldPathString
oPackage.contentsourcepath = sNewPathString
oPackage.put_
End If
Next
WScript.Echo "Done"
'====================================================
' SUB: Connects to the SMS Provider
'====================================================
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

Script 3 (Mind word wrapping)
'///////////////////////////////////////////////////
'
' SYNTAX: cscript remapDriverPkgs.vbs NEWSERVERNAME
'
'///////////////////////////////////////////////////////////
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
'====================================================
'== Execute SUB to connect to SCCM Provider
'====================================================
CONNSCCM()
For Each oPackage In oWbemServices.execquery("select * from sms_DriverPackage")
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
'WScript.Echo sOldPathString
oPackage.PkgSourcePath = sNewPathString
oPackage.put_
End If
Next
WScript.Echo "Done"
'====================================================
' SUB: Connects to the SMS Provider
'====================================================
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

Advertisements

4 thoughts on “SCCM: Migrating to a new source code server

  1. I get a failure on the script 2 ‘expected then’

  2. I fixed it by commenting ‘If WScript.Arguments.Count 1 Then
    ‘WScript.Echo “Wrong number of arguments were passed.”
    ‘WScript.Quit
    ‘End If

    Also the second script uses a search on dell latitude better leave it out or tell this in this post

  3. Oh yeah, I hadnt realized I left the “Latitude 13” If statement that I was using for validation. Simpy remove that If statement and you should be good.

    As far as commentning out that line to get past an error. Thats the same line in each script and is used to prevent the script from running with a potentially blank server name. Sounds like something wasn’t right with your copying and pasting the script. I would highly recommend NOT commenting out that statement.

  4. Thanks! saved me a lot of time.

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