为什么我的 PowerShell 脚本在 SCCM 中得到不正确的驱动程序 类?
Why am I getting incorrect driver classes in SCCM with my PowerShell script?
SCCM 版本:2012 R2
PowerShell 版本:3
操作系统:Windows Server 2008 R2 SP1
我已经编写了一个脚本,仅使用已签名的硬盘驱动器控制器 (HDC) 和网络 (NET) 驱动程序 classes 在 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?"
}
正如您在脚本中的某一时刻看到的那样,我输出了驱动程序 class 以便我可以手动验证驱动程序包的输出,所有输出的都是 hdc 或 net 驱动程序 classes.
首先,从驱动程序包中删除所有驱动程序,然后重试此脚本。我敢打赌,在某些时候您可能不小心将一些驱动程序添加到了这个包中,因此造成了这种混乱,因为否则您的脚本看起来很合理。
如果这不起作用,我会在您的脚本中的此时进行故障排除:
$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"
}
添加写入调试步骤,并在出现 PowerShell 调试提示时选择 'Suspend'。然后,您可以轻松解决 $drivers
内返回的驱动程序问题。
如果我不得不猜测,我会说过滤器可能没有按预期工作(当在更大的 -and 语句中时必须注意那些 -or 语句,可能会发生非常棘手的事情)。一个潜在的修复方法是将 -and ($_.DriverClass -eq "hdc" -or $_.DriverClass -eq "net")
语句移动到 Where-Object 过滤器中的最后一个语句。
据我所知,您的脚本没有任何问题。我正在研究类似的解决方案,但得到的结果与您相同。输出列表看起来不错,但是当将驱动程序添加到包中时,无论我做什么,我都会得到各种其他驱动程序。我要添加的驱动程序(在我的例子中只有 hdc)和添加的其余驱动程序的唯一共同点是源路径。如果在控制台中调出 "Content Source Path" 列,您可以看到 hdc 驱动程序与添加的其他驱动程序具有相同的源路径。所以我的结论是 Add-CMDriverToDriverPackage 将所有驱动程序添加到同一位置,而不管您在搜索字符串中指定的驱动程序。
我认为这是 cmdlet 设计的一个缺陷,甚至在 Technet 上的描述中也是这样说的:https://technet.microsoft.com/en-us/library/jj850173(v=sc.20).aspx “当将设备驱动程序添加到驱动程序包时,Microsoft System Center 2012 Configuration Manager 将设备驱动程序内容从驱动程序源位置复制到驱动程序包。"
SCCM 版本:2012 R2
PowerShell 版本:3
操作系统:Windows Server 2008 R2 SP1
我已经编写了一个脚本,仅使用已签名的硬盘驱动器控制器 (HDC) 和网络 (NET) 驱动程序 classes 在 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?"
}
正如您在脚本中的某一时刻看到的那样,我输出了驱动程序 class 以便我可以手动验证驱动程序包的输出,所有输出的都是 hdc 或 net 驱动程序 classes.
首先,从驱动程序包中删除所有驱动程序,然后重试此脚本。我敢打赌,在某些时候您可能不小心将一些驱动程序添加到了这个包中,因此造成了这种混乱,因为否则您的脚本看起来很合理。
如果这不起作用,我会在您的脚本中的此时进行故障排除:
$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"
}
添加写入调试步骤,并在出现 PowerShell 调试提示时选择 'Suspend'。然后,您可以轻松解决 $drivers
内返回的驱动程序问题。
如果我不得不猜测,我会说过滤器可能没有按预期工作(当在更大的 -and 语句中时必须注意那些 -or 语句,可能会发生非常棘手的事情)。一个潜在的修复方法是将 -and ($_.DriverClass -eq "hdc" -or $_.DriverClass -eq "net")
语句移动到 Where-Object 过滤器中的最后一个语句。
据我所知,您的脚本没有任何问题。我正在研究类似的解决方案,但得到的结果与您相同。输出列表看起来不错,但是当将驱动程序添加到包中时,无论我做什么,我都会得到各种其他驱动程序。我要添加的驱动程序(在我的例子中只有 hdc)和添加的其余驱动程序的唯一共同点是源路径。如果在控制台中调出 "Content Source Path" 列,您可以看到 hdc 驱动程序与添加的其他驱动程序具有相同的源路径。所以我的结论是 Add-CMDriverToDriverPackage 将所有驱动程序添加到同一位置,而不管您在搜索字符串中指定的驱动程序。
我认为这是 cmdlet 设计的一个缺陷,甚至在 Technet 上的描述中也是这样说的:https://technet.microsoft.com/en-us/library/jj850173(v=sc.20).aspx “当将设备驱动程序添加到驱动程序包时,Microsoft System Center 2012 Configuration Manager 将设备驱动程序内容从驱动程序源位置复制到驱动程序包。"