gpt4 book ai didi

powershell - powershell将.inf文件传递给pnputil

转载 作者:行者123 更新时间:2023-12-02 23:44:53 25 4
gpt4 key购买 nike

我试图递归搜索目录,在其中找到任何.inf文件,并将这些文件传递给pnputil以将这些驱动程序添加到Windows驱动程序目录中。

我有以下内容:

cd /drivers

$x = ls -Path . -Filter "*.inf" -Recurse -ErrorAction SilentlyContinue

Foreach ($i in $x){
pnputil /a $i
}

我从pnputil中收到以下错误:

Adding the driver package failed : Invalid INF passed as parameter.



我假设它失败了,因为pnputil不喜欢它得到的对象。关于通过什么或修改什么的任何建议?

谢谢!

最佳答案

您知道问题出在哪里。您正在将一个对象传递给命令行。您需要做的是从该System.IO.FileInfo对象中提取完整路径,然后传递给pnputil

Foreach ($i in $x){
& pnputil /a $i.FullName
}

那应该为您提供所需的结果。您可能要做的另一件事是更改 $x,使其成为文件名数组。 -ExpandProperty是重要的部分。
$x = ls -Path . -Filter "*.inf" -Recurse -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Fullname

Foreach ($i in $x){
pnputil /a $i
}

关于powershell - powershell将.inf文件传递给pnputil,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27324744/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com