I have this customer who had to move all driver packages from from one server a another. This of cause meant all the Data Source references had to be change as well.
Once al the packages were moved to the new server I ran the following two scripts to change the source. All you need to change is the $Site to your site code, or add it is a parameter when you run the script. You will obviously also have to type in the old and new path.
Syntax: Script.ps1 –Site XXX
If you want to only run against one driver/package for testing you can also add the ID as a parameter
Syntax: Script.ps1 –ID XXXXXXXX –Site XXX
Drivers
1 param($ID = "*",$Site = "CEN") 2 3 $drivers = Get-WmiObject SMS_Driver -Namespace root\SMS\site_$Site 4 5 $drivers | here-object{$_.ContentSourcePath -like "OldServer\OldShare\*" -and $_.PackageID -like $ID} | 6 ForEach-Object{$_.ContentSourcePath = $_.ContentSourcePath -replace "OldServer\\OldShare", "NewServer\\NEWShare"; $_.Put()}
Driver packages
1 param($ID = "*",$Site = "CEN") 2 3 $packages = Get-WmiObject SMS_DriverPackage -Namespace root\SMS\site_$Site 4 5 $packages | Where-object{$_.PkgSourcePath -like "*OldServer\OldShare*" -and $_.PackageID -like $ID} | 6 ForEach-Object{$_.PkgSourcePath = $_.PkgSourcePath -replace "OldServer\\OldShare","NewServer\NewShare"; $_.Put()}
Thanks for the awesome scripts! During a migration, I completely changed the driver destination folder structure, and these scripts made it so easy to update the source paths! One note though, you’re missing a “w” in the drivers script where it reads “here-object”.
Cheers!
Hi, this is the script that I was looking for 🙂 But couldn’t make it work, I’m sure you have tried and tested it before you put it here but that double slashes confused me. I also tried to run it with package id but nothing happened. I have changed the driver packages’ content sources manually but I also have around 800 drivers to be changed. Is there any ID for individual drivers?
For drivers, it’s not PackageID, but CI_ID:
$drivers | here-object{$_.ContentSourcePath -like “OldServerOldShare*” -and $_.CI_ID -like $ID} |
Also nice to know: in the replace, the string “” should be like this: “\”, but only in the first string:
ForEach-Object{$_.ContentSourcePath = $_.ContentSourcePath -replace “\\OldServer\OldShare”, “\NewServerNEWShare”; $_.Put
But thanks for the script! It helped me a lot!
Hey Ben, you missed the comment by squidjigg!!! peeps, don’t forget to change here to where…hey blog owner, please update this blog entry so it has the correct syntax. Other than that, it works.T
Also worth noting is that any hidden shares, ie, ones with a “$” sign will need to have the any dollar signs escaped with an additional backslash, only required in the string to find.
Otherwise, thanks for the great script.
Example:
1 param($ID = “*”,$Site = “CEN”)
2
3 $drivers = Get-WmiObject SMS_Driver -Namespace rootSMSsite_$Site
4
5 $drivers | where-object{$_.ContentSourcePath -like “OldServerOldShare$*” -and $_.PackageID -like $ID} |
6 ForEach-Object{$_.ContentSourcePath = $_.ContentSourcePath -replace “OldServer\OldShare$\”, “NewServer\NEWShare$”; $_.Put()}
Not sure what I’m doing wrong here. This is what I’m getting when I try to run the script.
Property ‘ContentSourcePath’ cannot be found on this object; make sure it exists and is settable.
At C:Userscarterjrupdate_drivers.ps1:4 char:19
+ ForEach-Object{$_. <<<< ContentSourcePath = $_.ContentSourcePath -replace "usas24\data sources for sccm", "usas11\d
ata sources for sccm"; $_.Put()}
+ CategoryInfo : InvalidOperation: (ContentSourcePath:String) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
You cannot call a method on a null-valued expression.
At C:Userscarterjrupdate_drivers.ps1:4 char:141
+ ForEach-Object{$_.ContentSourcePath = $_.ContentSourcePath -replace "usas24\data sources for sccm", "usas11\data so
urces for sccm"; $_.Put <<<< ()}
+ CategoryInfo : InvalidOperation: (Put:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Here is the script as I edited it. Obviously my old server is usas24 and the new one is usas11. The paths are all the same.
param($ID = "*",$Site = "US2")
$drivers | where-object{$_.ContentSourcePath -like “usas24\data sources for sccm*” -and $_.CI_ID -like $ID}
ForEach-Object{$_.ContentSourcePath = $_.ContentSourcePath -replace "usas24\data sources for sccm", "usas11\data sources for sccm"; $_.Put()}
Any help would be greatly appreciated as there are hundreds of drivers to be remapped.
Thanks,
Rusty
Figured out the problem script worked fine once I made the necessary corrections.
Had to make a few adjustments in order to get this working.
$drivers = Get-WmiObject SMS_Driver -Namespace rootSMSsite_002
$drivers | where-object{$_.ContentSourcePath -like “\oldserverSource$Drivers*” -and $_.Package_ID-like $ID} | ForEach-Object{$_.ContentSourcePath = $_.ContentSourcePath -replace “\\OLDSERVER\Source$\Drivers”, “\\company.localdfssccmsources$Drivers”; $_.Put()}
Really useful script!
Just a note of caution however, use caution when running this against many driver packages since the Put() method forces an update on the package to all DP’s, if you do this to many at once then you might be in for some pain, task sequences may stop running etc.. At least this is the case for SCCM 2007 SP2 R3, I haven’t tested others.
An alternative it to do the same via TSQL directly in the database. Don’t normally recommend direclty modifying the database but in this case it makes some sense since this doesn’t trigger the package refresh, and the TSQL statement runs much faster too 🙂
TSQL can easily be run for Driver Package
SELECT
pkgSourcePath
, REPLACE(pkgSourcePath,’\sp-v-sccm’,’\sp-v-sccm-cb’) AS NewContentSourcePath
FROM dbo.v_package
WHERE pkgSourcePath LIKE ‘%\sp-v-sccm%’
but as for the driver, it is not possible with just SQL, cause:
The complete “Driver Source” (including driver file name) is not a simple field within any of the SCCM tables. As it turns out, driver information is embedded within an XML field called SDMPackageDigest that itself is part of the CL_ConfigurationItems table.
as per http://www.laurierhodes.info/?q=node/73
It does nothing with SCCM 2012 R2
No replacement happens at all (and no error)