When doing OSD in ConfigMgr 2012 SP1 you always have to deal with drivers. When dealing with drivers, you should ask yourself if you’d like to trust the Plug and Play method that ConfigMgr 2012 SP1 uses, or if you want total control over what drivers get injected into the OS on the system that you’re deploying. As Johan Arwidmark and Mikael Nyström would call it, either TC or TC (Total Caos or Total Control).
The usual process of manually creating each Driver Package through the console is time demanding. Why not ease up this process by using PowerShell and save yourself alot of time? I like to save time and get tasks done as quickly as possible, so I wrote a PowerShell script to create a folder structure in the ContentLibrary$ share and create all the Driver Packages.
Overview
- The script
- How the script works
- Usage of the script
The script
Save this script as Create-DriverPackages.ps1 and put it in a folder on your Primary Site server. I’ve choosen to put it in E:\Scripts.
param(
[parameter(Mandatory=$true)]
$SiteServer,
[parameter(Mandatory=$true)]
$SiteCode,
[parameter(Mandatory=$true)]
$ContentPath,
[parameter(Mandatory=$true)]
$ImportModelsFrom ) $ModulePath = (($env:SMS_ADMIN_UI_PATH).Substring(0,$env:SMS_ADMIN_UI_PATH.Length-5)) + ‘\ConfigurationManager.psd1’ Import-Module $ModulePath -Force if ((Get-PSDrive $SiteCode -ErrorAction SilentlyContinue | Measure-Object).Count -ne 1) { New-PSDrive -Name $SiteCode -PSProvider “AdminUI.PS.Provider\CMSite” -Root $SiteServer } $SiteDrive = $SiteCode + “:” $DriverSourcePath = $ContentPath + “\” + “DriverSources” + “\” + “Windows 7 x64” + “\” + “Dell” $DriverPackagePath = $DriverSourcePath.Replace(“Sources”,”Packages”) try { if (Test-Path -PathType Container $ContentPath) { New-Item -Path $DriverSourcePath -ItemType Directory -ErrorAction Stop | Out-Null New-Item -Path $DriverPackagePath -ItemType Directory -ErrorAction Stop | Out-Null } else { Write-Output “ERROR: The specified path for ContentPath was not found” } } catch { Write-Output “ERROR: $($_.Exception.Message)” } $ImportArray = Get-Content -Path $ImportModelsFrom $ImportArray | ForEach-Object { if (Test-Path -PathType Container ($DriverSourcePath + “\” + $_)) { Write-Output “INFO: $($DriverSourcePath)\$($_) already exists” } else { New-Item -Name $_ -Path $DriverSourcePath -ItemType Directory | Out-Null Write-Output “INFO: Created driver source folder $($_)” } if (Test-Path -PathType Container ($DriverPackagePath + “\” + $_)) { Write-Output “INFO: $($DriverPackagePath)\$($_) already exists” } else { New-Item -Name $_ -Path $DriverPackagePath -ItemType Directory | Out-Null Write-Output “INFO: Created driver package folder $($_)” } } $ChildItems = Get-ChildItem -Path $DriverSourcePath $ChildItems | ForEach-Object { $CurrentObject = $_.Name if (Get-WmiObject -Namespace “root\SMS\site_$($SiteCode)” -Class SMS_DriverPackage | Where-Object {$_.Name -eq $CurrentObject}) { Write-Output “INFO: Driver Package $($_.Name) already exists” } else { $PackageName = $_.Name $DriverPackage = ([WMIClass]”\\$($SiteServer)\root\SMS\site_$($SiteCode):SMS_DriverPackage”).CreateInstance() $DriverPackage.Name = “$($PackageName)” $DriverPackage.PkgSourcePath = “$($DriverPackagePath)\$($PackageName)” $DriverPackage.PkgSourceFlag = 2 $DriverPackage.Put() | Out-Null Write-Output “INFO: Creating Driver Package $($_.Name)” } } Set-Location $siteDrive $i = 1 $DPG = @{0 = “Name”} $DPG.Remove(0) $GetDPG = Get-CMDistributionPointGroup | Select-Object Name | ForEach-Object { $DPG += @{$i = $_.Name} $i++ } $DPG.GetEnumerator() | Select-Object @{Label=”#”;Expression={$_.Name}},Value | Sort-Object “#” | Format-Table -AutoSize $DistributeAnswer = Read-Host “Please enter your selection and press Enter” $DPGName = $DPG.Get_Item([int]$DistributeAnswer) Write-Output “” $DriverPackages = Get-CMDriverPackage $DriverPackages | ForEach-Object { $DriverPackageID = $_.PackageID Write-Output “Starting distribution for driver package: $($_.Name)” Start-CMContentDistribution -DriverPackageId $DriverPackageID -DistributionPointGroupName $DPGName } Set-Location C:
How the script works
The script consists of two components, the script itself and a text file with the computers models. You should start of with entering the model names of your Dell systems in a text file, save and call it e.g. ComputerModels.txt. When the script is launched with “\\fileserver\ContentLibrary$\OSD” as the value for the ContentPath parameter, the following folder structure will be created:
- ..\DriverSources
- ..\DriverPackages
- ..\DriverSources\Windows 7 x64
- ..\DriverPackages\Windows 7 x64
- ..\DriverSources\Windows 7 x64\Dell
- ..\DriverPackages\Windows 7 x64\Dell
When the folder structure creation has completed, it will then create the Driver Packages on the Primary Site server specified with the SiteServer and SiteCode parameters. In the end you’ll be asked to what Distribution Point Groups you’d like to distribute the newly created Driver Packages. NOTE! The script will enumerate all Driver Packages and distribute them to the selected Distribution Point Group. If you have any Driver Packages created in the past, and don’t want them to be distributed as well, you should at this point exit out of the script by pressing CTRL+C.
Usage of the script
1. Create a new text file in E:\Temp and call it ComputerModels.txt.
2. Enter the models that you want to create driver packages for.
3. Save the text file.
4. Open an elevated PowerShell 32-bit command prompt.
5. Run the following command:
.\Create-DriverPackages.ps1 -ContentPath "<PATH_TO_YOUR_CONTENT_LIBRARY>" -SiteServer <YOUR_SITE_SERVER> -SiteCode <YOUR_SITE_CODE> -ImportModelsFrom E:\Temp\test.txt
6. Select the Distribution Point Group you’d like to distribute the newly created Driver Packages to and press Enter.
7. The Driver Packages are now created, and can be found in the Configuration Manager Console.
You’d now have to download and extract your driver files into the created folder structure (in the DriverSources folder) and then import them into ConfigMgr 2012 SP1. Atleast you don’t have to manually create a lot of folders and Driver Packages!
Thanks for sharing your script.
Is possible to add more model in textfiles like Dell and HP
Latitude E6320
Latitude E6330
Latitude E6420
Latitude E6430
Latitude E6510
EliteBook 8760W
EliteBook 5000
And If I wont make folder for X64 and X86 like this script.How I can use in your script
Iem not expert I powershell just know something about it
$SiteDrive = $SiteCode + “:”
$DriverSourcePath = $ContentPath + “\” + “DriverSources” + “\” + “Windows 7 x64” + “\” + “Dell”
$DriverSourcePath = $ContentPath + “\” + “DriverSources” + “\” + “Windows 7 x86” + “\” + “Dell”
$DriverSourcePath = $ContentPath + “\” + “DriverSources” + “\” + “Windows 7 x64” + “\” + “HP”
$DriverSourcePath = $ContentPath + “\” + “DriverSources” + “\” + “Windows 7 x86” + “\” + “HP”
$DriverPackagePath = $DriverSourcePath.Replace(“Sources”,”Packages”)
I got just last be made with script
“Windows 7 x86” + “\” + “HP”
How I can use this script with your script.
Param(
$Folder=”C:\Downloads\Drivers”,
$archs = “x86″,”x64”,
$OSs = “Windows PE”,”Windows XP”,”Windows 7″,”Windows 8″,
$Makes = “Dell Inc.”,”Hewlett-Packard”,”Microsoft Corporation”,”VMware, Inc”
)
foreach ($arch in $archs) {
foreach ($OS in $OSs) {
foreach ($make in $Makes) {
New-Item -path “$Folder\$OS $arch” -Name “$Make” -Type directory
}
}
}
Hi Savo,
I’ll look into a way of combining or perhaps create a second script for HP’s drivers. I’m currently on vacation but will get back to you soon!
Regards,
Nickolaj