Uncategorized · March 13, 2021 0

using “Select” & “Where” in your queries

Hi there,

one of the important things an administrator should be good at, is filtering his queries to get the best result possible.

No matter what PowerShell commands you are using, there are always possibility to pipeline the result of your main command and get the result filtered or customized. Now I will take some examples and show you how to use Select-Object and where-object

open ISE and write Get-service

as you see above, the output will be a table of Status, Name and Display name.

Now, lets assume you only want to display the name list and you are not interested in the status. for that you will use Select

Now lets assume you have a scenario where you want to check if a service named spooler exist and you don’t want to read through the list manually. This mean, you will use where as a condition for your search

Well, PowerShell is more than that 😉 .. let me show you an example and then explain

as you see, the command Get-WindowsFeature will show you a table of features of different states (installed, available, etc..); it shows the name and display Name for each Feature.

now if you want to display only installed Features; I guess you know the answer from the previous example

Now lets unleash the Power of PS! 😀 PS can understand the structure of the output and you can do the above request will less work! see below

Now, lets assume you are interested only in showing the names of the installed features

so if you want to check if the DNS feature is installed on a server, you would be running the command

as you see above, you can use where and select multiple times in your command and you decide which one comes first.

have fun

cheers

Jaber

Close Bitnami banner
Bitnami