powershell pass .inf files to pnputil

8.9k views Asked by At

I am trying to recursively search a directory, find any .inf files within and pass those files to pnputil to add those drivers to windows drivers directory.

I have the following:

cd /drivers

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

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

and I get the following error from pnputil:

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

I am assuming it's failing because pnputil doesn't like the object it's getting. Any suggestion as to what to pass it, or what to modify?

Thank you!

1

There are 1 answers

1
Matt On BEST ANSWER

You knew what the issue was. You are passing an object to the command line. What you need to do is extract the full path from that System.IO.FileInfo object to pass to pnputil

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

That should get you the results you are looking for. Another thing you could have done was change $x so that it was an array of file names. -ExpandProperty being the important part.

$x = ls -Path . -Filter "*.inf" -Recurse -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Fullname

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