Get the App
SLTechnology News&Howtos  ›  Servers  › 

Examples of the usage of PowerShell Where-Object

Shulou Source: shulou.com Published: 2022-06-02 07:18:20 09月11日 Update

The FilterScript value is a script block that evaluates to True or False, that is, one or more Windows PowerShell commands surrounded by curly braces {}. These script blocks may be very simple, but you need to understand another concept about Windows PowerShell, the comparison operator, to create them. The comparison operator compares the items displayed on each side of it. The comparison operator begins with the "-" character, followed by the name. The basic comparison operator applies to almost any type of object. More advanced comparison operators may apply only to text or arrays.

Here are some sample commands, from simple to complex

Get-WmiObject-Class Win32_SystemDriver | Where-Object-FilterScript {$_ .State-eq 'Running'}

Get-WmiObject-Class Win32_SystemDriver | Where-Object-FilterScript {$_ .State-eq "Running"} | Where-Object-FilterScript {$_ .StartMode-eq "Auto"}

Get-WmiObject-Class Win32_SystemDriver | Where-Object-FilterScript {$_ .State-eq "Running"} | Where-Object-FilterScript {$_ .StartMode-eq "Manual"} | Format-Table-Property Name,DisplayName

Get-WmiObject-Class Win32_SystemDriver | Where-Object-FilterScript {($_ .State-eq 'Running')-and ($_ .StartMode-eq' Manual')} | Format-Table-Property Name,DisplayName

In addition to the comparison operators listed above, there are some logical operators that can also be used with where-object

You can also follow the official Wechat account below for more information.

Tags: Operators operations commands scripts examples complex advanced one-sided public name followed multiple characters objects opening parentheses arrays text more concepts Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Microsoft Docker Redmi Huawei