How do I filter out a string with a wildcard and output it into another text file with a modification?

0

I want to uninstall all the third party drivers from a Windows image using DISM but it seems it does not accept wildcards. This means I would have to uninstall them all manually which I want to avoid. So far I've created a list of all the drivers in a table format as seen in the image below:

enter image description here

I have two options as far as I can see:

  • Use the bash subsystem in Windows 10
  • Use PowerShell.

I only care about the oem*.inf part. However beyond just filtering out just the oem*.inf text I would like to amend it to be as so:

/Driver:oem100.inf /Driver:oem101.inf /Driver:oem102.inf /Driver:oem103.inf

etc, in line and not in a list format.

I thought I could do this with grep, but my skills in Linux are not as good as I would like them to be. Using PowerShell seems promising but again I'm not advanced enough yet. How can I achieve this?

David Prentice

Posted 2016-11-11T00:50:08.587

Reputation: 137

Answers

1

Here's a PowerShell solution:

$File = "Drivers.txt"
$RegEx = '^oem\d{1,3}.inf'
$Drivers = Select-string $File -Pattern $regex|%{[string]$_.Matches}
$ofs = " /Driver:"
$String="/Driver:"+"$Drivers"
$String | Out-File DriverString.txt

A small test file gave this result:

/Driver:oem100.inf /Driver:oem101.inf /Driver:oem102.inf /Driver:oem103.inf /Driver:oem104.inf /Driver:oem105.inf /Driver:oem106.inf /Driver:oem107.inf /Driver:oem108.inf /Driver:oem109.inf

LotPings

Posted 2016-11-11T00:50:08.587

Reputation: 6 150