简体   繁体   中英

Powershell Start-Process pnputil.exe

I'm trying to run pnputil with start-process, but it doesn't seem to work.

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 :

$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 $() . Instead, try this

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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