Tuesday, July 29, 2014

Using the Where-Object in Powershell

Earlier I posted some scripts that I use with my Hyper-V instances to reduce clicking and mentioned filtering.  To Filter, just use a Where-Object like so:

Get-VM | Where-Object{$_.Name -Like "SQL*"} | Stop-VM

It makes the scripts from before more powerful, especially if you use some standard naming conventions for your lab VMs.  Technet has a good coverage of the parameters you can use in a Where-Object, but I mainly use the -Like comparison operator to match regular expressions.

No comments:

Post a Comment