简体   繁体   English

Powershell 启动进程 pnputil.exe

[英]Powershell Start-Process pnputil.exe

I'm trying to run pnputil with start-process, but it doesn't seem to work.我正在尝试使用 start-process 运行 pnputil,但它似乎不起作用。

Here is a script that works without start-process:这是一个无需启动过程即可工作的脚本:

$Driver = Get-ChildItem "$PSScriptRoot" -Recurse -Filter "*inf"

$InstallDriver = foreach ($item in $Driver) {
          
PNPUtil.exe /add-driver $item.FullName /install

}

But if I'm doing the same with start-process I cant get it to work :但是如果我对 start-process 做同样的事情,我就无法让它工作:

$Driver = Get-ChildItem "$PSScriptRoot" -Recurse -Filter "*inf"

$InstallDriver = foreach ($item in $Driver) {
          
Start-Process PNPUtil.exe /add-driver $item.FullName /install

}

I have also tried我也试过

Start-Process PNPUtil -ArgumentList '/add-driver $item.FullName /install'

Start-Process PNPUtil -ArgumentList '/add-driver "$item.FullName" /install'

Start-Process PNPUtil -ArgumentList '/add-driver "${$item.FullName}" /install'

Start-Process PNPUtil -ArgumentList "/add-driver "${$item.FullName}" /install'

Start-Process PNPUtil -ArgumentList "/add-driver $item.FullName} /install"

But it doesn't work但它不起作用

Does anyone know why it does not work?有谁知道为什么它不起作用? Thanks for the help谢谢您的帮助

They are all separate arguments.它们都是单独的参数。 Single quotes around variables will prevent the variable from expanding plus if you enclose $variable.property in double quotes you need a subexpression $() .变量周围的单引号将阻止变量扩展,如果将$variable.property括在双引号中,则需要一个子表达式$() Instead, try this相反,试试这个

Start-Process PNPUtil -ArgumentList "/add-driver",$item.FullName,"/install"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM