SCCM版本:2012 R2
PowerShell版本:3
操作系统:Windows Server 2008 R2 SP1
我编写了一个脚本,只使用签名的硬盘驱动器控制器(HDC)和网络(NET)驱动程序类在SCCM中创建驱动程序包,但我在SCCM中显示各种驱动程序。
我希望这不会发布错误的地方,因为这个问题需要了解SCCM和PowerShell。
这是脚本:
#Vars
$site = "SITENAME:"
$configMgrCmdLets = "D:\Program Files\Microsoft Configuration Manager\AdminConsole\bin\ConfigurationManager.psd1"
$DriverPackagePath = "\\ServerName\sources\DriverPacks\PE\SignedBootDrivers"
$DriverPackageName = "Signed Boot Drivers"
$MaxQueryResults = 4000
#pre-reqs
Import-Module $configMgrCmdLets
Set-Location $site
if (get-cmSite)
{
#all good, let's proceed.
Set-CMQueryResultMaximum -Maximum $MaxQueryResults
#Does the driverpackage already exist? If not, Create it.
if (!(Get-cmDriverPackage -Name $DriverPackageName))
{
New-CMDriverPackage -Name $DriverPackageName -Path $DriverPackagePath -PackageSourceType StorageDirect
}
$drivers = Get-CMDriver | Where-Object `
{
$_.IsSuperseded -eq $false `
-and $_.IsEnabled -eq $true `
-and $_.IsHidden -eq $false `
-and $_.DriverSigned -eq $true `
-and ($_.DriverClass -eq "hdc" -or $_.DriverClass -eq "net") `
-and $_.SDMPackageXML -match "x64 Windows 8"
}
ForEach ($driver in $drivers)
{
Add-CMDriverToDriverPackage -Driver $driver -DriverPackageName $DriverPackageName
#Output the driver class so that I can verify the result is HDC or NET.
$driver.DriverClass
}
}
else
{
Write-Error -Message "Can't read Site: $site. Perhaps the SCCM CmdLets were not imported?"
}
正如您在脚本中的某一点上所看到的,我输出了驱动程序类,以便我可以手动验证驱动程序包的输出,并且输出的所有内容都是hdc或net驱动程序类。
答案 0 :(得分:1)
从我所看到的,你的脚本没有任何问题。我正在研究类似的解决方案,但我得到的结果和你一样。输出列表看起来不错,但是当将驱动程序添加到包中时,无论我做什么,我都会得到所有类型的驱动程序。我想要添加的驱动程序(在我的情况下只有hdc)和添加的其他驱动程序的唯一共同点是源路径。如果在控制台中显示“内容源路径”列,则可以看到hdc驱动程序与添加的其他驱动程序具有相同的源路径。所以我的结论是Add-CMDriverToDriverPackage将所有驱动程序添加到同一位置,而不管搜索字符串中指定的是什么。
我认为这是cmdlet设计中的一个缺陷,它甚至在Technet上的描述中也这样说:https://technet.microsoft.com/en-us/library/jj850173(v=sc.20).aspx“当设备驱动程序添加到驱动程序包时,Microsoft System Center 2012配置Manager将设备驱动程序内容从驱动程序源位置复制到驱动程序包。“
答案 1 :(得分:0)
首先,首先从驱动程序包中删除所有驱动程序,然后再次尝试此脚本。我在某些时候打赌你可能不小心在这个软件包中添加了一些驱动程序,因此这种混乱,因为否则你的脚本看起来很健全。
如果这不起作用,我会在您的脚本中进行故障排除:
$drivers = Get-CMDriver | Where-Object `
{
$_.IsSuperseded -eq $false `
-and $_.IsEnabled -eq $true `
-and $_.IsHidden -eq $false `
-and $_.DriverSigned -eq $true `
-and ($_.DriverClass -eq "hdc" -or $_.DriverClass -eq "net") `
-and $_.SDMPackageXML -match "x64 Windows 8"
}
添加写入 - 调试步骤,然后选择“暂停”#39;出现PowerShell调试提示时。然后,您可以轻松解决$drivers
内返回的驱动程序问题。
如果我不得不猜测,我会说过滤器可能没有按照需要工作(当在更大的声明内部时,必须注意那些 - 或语句,可能会发生非常棘手的事情)。可能的解决方法是将-and ($_.DriverClass -eq "hdc" -or $_.DriverClass -eq "net")
语句移动到Where-Object过滤器中的最后一个语句。