Monday, January 9, 2012

Creating Your Own Get-Driver Tool using PowerShell


PowerTip of the Day, from


Creating Your Own Get-Driver Tool

Some code snippets are really valuable, so you should turn them into functions to keep around as new PowerShell commands. Here's a sample function:

function Get-Driver {


    $Keyword = '*'


  $col1 = @{Name='File Name'; Expression={ Split-Path $_.Path -Leaf } }

  driverquery.exe /v /FO CSV |

    ConvertFrom-CSV |

    Select-Object 'Display Name',  'Start Mode', 'Paged Pool(bytes)', $col1 |

    Where-Object { ($_ | Out-String -Width 300) -like "*$Keyword*" }


You now have a function called Get-Driver which lists you all drivers. With just one parameter, you can also easily filter the driver list:

PS> Get-Driver mount


Display Name                     Start Mode          Paged Pool(bytes)          File Name

------------                     ----------          -----------------      ---------

Mount Point Manager Boot                         65.536                                         mountmgr.sys

WIMMount                                Manual                    4.096                                           wimmount.sys



PS> Get-Driver disable


Display Name                     Start Mode          Paged Pool(bytes)            File Name

------------                     ----------          -----------------            ---------

CD/DVD File Syst... Disabled               69.632                                         cdfs.sys

Crcdisk filter D... Disabled               4.096                                            crcdisk.sys

udfs                                           Disabled              180.224                                       udfs.sys

Winsock IFS Driver      Disabled              12.288                                          ws2ifsl.sys

It is a grep-like filter feature which returns all drivers that have your keyword in one of its properties.



No comments:

Post a Comment