Pnp-DisableDevice 实例 ID 返回为空值

问题描述 投票:0回答:1

我们的业务存在一个问题,即英特尔显示驱动程序版本 31.0.101.* 不断取代任何新版本,并且驱动程序 31 是 Citrix 和组织使用的其他工具的已知问题。英特尔在其支持页面上表示,关于这个已知有问题的驱动程序,请保留 31 安装,但从其网站下载驱动程序修订版 32.0.101.*。我想实现一个 SCCM 脚本(因为很多机器已经安装了驱动程序 32,并且在强制更新日后才切换回驱动程序 31)禁用驱动程序 31 并启用驱动程序 32。

我当前的代码片段是这样的:

$Driver31 = "31.0.101."
$Driver32 = "32.0.101."

$oldDriver = Get-PnpDevice | Where-Object { $_.Version -like $Driver31 }

$newDriver = Get-PnpDevice | Where-Object { $_.Version -like $Driver32 }

if ($oldDriver) {
    Disable-PnpDevice -InstanceId $oldDriver.InstanceId -Confirm:$false
}

运行此命令时,我收到一条错误,指出

.InstanceId
是空值。我在这里做错了什么?

powershell
1个回答
0
投票
如果您尝试获取不存在的属性,PowerShell 不会给您提示,因此当您查询不存在的

$_.Version

 属性时,您不会收到任何反馈。要检查可用的属性,请运行:

Get-PnpDevice | Get-Member
这将返回一个属性列表 - 其中 

Version

 不是一个选项:

Name MemberType Definition ---- ---------- ---------- Class AliasProperty Class = PNPClass FriendlyName AliasProperty FriendlyName = Name InstanceId AliasProperty InstanceId = DeviceID Problem AliasProperty Problem = ConfigManagerErrorCode
因此,您必须首先找到您感兴趣的设备,查询如下:

$devices = Get-PnpDevice | Where-Object {$_.FriendlyName -like "*Citrix*"}
然后在每个实例上使用 

Get-PnpDeviceProperty

 cmdlet 来查找具有旧驱动程序版本的实例 - 例如对于找到的第一个设备:

$version = Get-PnpDeviceProperty -InstanceId $d.InstanceId | Where-Object { $_.KeyName -like '*Version*'} | Select-Object -ExpandProperty Data
(通过一次添加每个管道部分来运行命令,以了解此处的中间步骤)

找到要禁用的设备后,请使用

Disable-PnpDevice

© www.soinside.com 2019 - 2024. All rights reserved.