0

I am writing a Powershell script to "build" Windows 7 PCs: adding users, printers, applications, changing settings, et al. I am adding some printer drivers using PNPUtil, but the problem is I won't know what "Published name" the drivers will be given.

If I put the output from the PNPUtil command into a .txt file, is there a way for me to then take the __.inf Published name and put it into a variable so that I can then use that name to add the printer using $printerclass.CreateInstance()?

2 Answers 2

2

You don't have to use a file if PNPUtil only outputs the name your interested in. That is, you can assign its output to a variable like so:

$result = pnputil.exe

BTW if you want to use a file, to read content from a file you use Get-Content:

pnputil.exe > result.txt
$result = Get-Content result.txt
$line = $result | Foreach {if ($_ -match 'assigned an (\w+\.inf)') {$matches[1]}}
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you, Keith - getting closer. Here is what the PNP add command outputs - "Microsoft PnP Utility Processing inf : AW3N_64PPD.INF Driver package added successfully. Published name : oem231.inf Total attempted: 1 Number successfully imported: 1" It will always be assigned an "oem000.inf" with the "000" being a number. So I need to get that "oem___.inf" and put that into a variable. Which was why I figured I could pipe the output into a .txt file and look for the "oem*.inf".
Sorry - the comments leave out the look of the file - there are a couple of blank lines in there.
Okay - I found my own solution: Once the .inf file is added, the driver names are stored in the Microsoft update files. I just need to know the specific name of the driver I need from each .inf file in order to add the Printers. ............ However, I'd still love to know how to get a string from a line from a file using Powershell.
0

Okay - I found my own solution: Once the .inf file is added, all the driver names in that .inf are stored in the Microsoft update files. I just need to know the specific name of the driver I need from each .inf file in order to add the Printers.

However, I'd still love to know how to get a string from a line from a file using Powershell.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.