A sample script for viewing Drivers in the driver store for site LAB, on server MyConfigMGRLABServer, that start with the path "C:\testdrivers\"
gwmi sms_driver -namespace root\sms\site_lab -Computer MyConfigMGRLABServer| `
? {$_.ContentSourcePath -like "C:\testdrivers\*"}
A sample script to DELETE the drivers (use caution - this is a delete . )
gwmi sms_driver -namespace root\sms\site_lab -Computer MyConfigMGRLABServer| `
? {$_.ContentSourcePath -like "C:\testdrivers\*"} | foreach {$_.Delete()}
Notice that this second script contains everything from the first script, with the addition of | foreach {$_.Delete()}
The following is a brief explanation of each part of the Command line.
| gwmi | abbreviation for get-wmiobject - used to query WMI in PowerShell |
| SMS_Driver | WMI Class (click the link for more details) |
| -namespace root\sms\site_lab | This is the WMI Namespace for SMS (the last three characters are the site code) |
| -computer MyconfigMGRLABServer | Alows us to specify the computer where the WMI Class/Namespace exists - if you're running this locally on the site, you do not need to specify the parameter |
| | | the PowerShell Pipeline - you could run everything that appears before this first pipeline, and view that data if you'd like. . we're using the Pipeline to pipe that information to the 'where' |
| ` | the tick mark - line continuation character. . copy both lines into one line to run, and you won't need it. |
| ? | abbreviation for 'where' - so everything in between "{" and "}" are used for the where clause |
| {$_.ContentSourcePath -like "C:\testdrivers\*"} | $_ - the pipeline variable also a nice demo here - it's the placeholder for the current object - so think of it as looking at every instance of SMS_Driver, and matching the ContentSourcePath to be like "C:\testdriver\*" (notice the * wildcard) |
| | | pipeline again |
| foreach | the is the for-each loop, so everything in between "{" and "}" will be performed for each instance. |
| $_.Delete() | Deletes the current instance of the object. |
So that's the command line in a nutshell. When I'm working on something like this, I take the time to write a little bit at a time - work to each pipeline, and make sure you're seeing the results you expect. Once you know exactly what it's going to do, then call the method required (in this case, Delete()).
Happy Coding!
ramseyg@hotmail.com