Reputation: 17223
I have the following command
Get-WindowsDriver -Online -All | where {$_.ClassName -like "Display"}
This gives me the result like this
Driver : vrd.inf
OriginalFileName : C:\Windows\System32\DriverStore\FileRepository\vrd.inf_amd64_3a0ba97737bffd01\vrd.inf
Inbox : True
ClassName : Display
BootCritical : False
ProviderName : Microsoft
Date : 6/21/2006 12:00:00 AM
Version : 10.0.18362.329
Driver : wvmbusvideo.inf
OriginalFileName : C:\Windows\System32\DriverStore\FileRepository\wvmbusvideo.inf_amd64_483a786e00a2cb7a\wvmbusvideo.inf
Inbox : True
ClassName : Display
BootCritical : False
ProviderName : Microsoft
Date : 6/21/2006 12:00:00 AM
Version : 10.0.18362.1
Now I want to extract only the OriginalFileName line of both results so my output would look like this
OriginalFileName : C:\Windows\System32\DriverStore\FileRepository\vrd.inf_amd64_3a0ba97737bffd01\vrd.inf
OriginalFileName : C:\Windows\System32\DriverStore\FileRepository\wvmbusvideo.inf_amd64_483a786e00a2cb7a\wvmbusvideo.inf
Now to obtain the above result i can do this
Get-WindowsDriver -Online -All | where {$_.ClassName -like "Display"} | findstr OriginalFileName
but the problem with the above command is that findstr has a character limit from what I have read, because of that some of the paths are cut. So in order to resolve that I am trying to use Select-String. This is what I am doing
Get-WindowsDriver -Online -All | where {$_.ClassName -like "Display"} | Select-String -Pattern "OriginalFileName"
but I am not getting any results. Any suggestions on what I might be doing wrong ?
Upvotes: 0
Views: 964
Reputation: 27428
Sometimes findstr is a good search technique. /i
makes it case insensitive.
Sometimes select-string or where { $_ -match 'whatever' } works. It depends on how the object converts to a string.
[pscustomobject]@{name='joe'},[pscustomobject]@{name='bill'} | select-string b
@{name=bill}
[pscustomobject]@{name='joe'},[pscustomobject]@{name='bill'} | where { $_ -match 'b' }
name
----
bill
Unfortunately get-windowsdriver just converts to "Microsoft.Dism.Commands.BasicDriverObject":
$a = Get-WindowsDriver -Online -All | where ClassName -eq Display
$a[0].ToString()
Microsoft.Dism.Commands.BasicDriverObject
$a | select-string dism
Microsoft.Dism.Commands.BasicDriverObject
Microsoft.Dism.Commands.BasicDriverObject
Microsoft.Dism.Commands.BasicDriverObject
Upvotes: 0
Reputation: 61028
Since Get-WindowsDriver returns objects (Microsoft.Dism.Commands.BasicDriverObject and/or Microsoft.Dism.Commands.AdvancedDriverObject), you should not use Select-String to find a single property of these objects.
Simply return them like
(Get-WindowsDriver -Online -All | Where-Object {$_.ClassName -like "Display*"}).OriginalFileName
If you want the output to look like PropertyName: PropertyValue
, you could use
Get-WindowsDriver -Online -All | Where-Object {$_.ClassName -like "Display*"} |
Select-Object OriginalFileName | Format-List
Upvotes: 1