What are Filters in PowerShell?

Muhammad Khan
Muhammad Khan

Posted On: Feb 22, 2018

 

A lot of commands in the PowerShell return values that are not always useful. To get useful return objects from the commands we can use filters. Filters can be created using the Filter parameter or even using the Where-Object. We can use the Filter parameter with the Get-ChildItem to get the items that we specified in the filter.

//example 
PS> Get-ChildItem -Path C:\folder\ -Filter '*1*.txt'

The above command filters and returns the files with a prefix as ‘1’. The same result can be achieved using the Where-Object, but generally, the filter is much faster than the Where-Object.

    Related Questions

    Please Login or Register to leave a response.

    Related Questions

    PowerShell Interview Questions

    What is PowerShell?

    PowerShell is a command-line tool built upon the .NET framework to help the windows system administrator. With PowerShell, you can control your system operations such as accessing data storage, regist...

    PowerShell Interview Questions

    How to run a PowerShell script?

    To run a script in the PowerShell, go to the directory where your script is stored on your PowerShell command. Then, run the script by typing the following command. PS C:\script_folder> ./Script.p...

    PowerShell Interview Questions

    How to check powershell version in Windows?

    Open your PowerShell command and type the following command to find the version, PS C:\> $PSVersionTable.PSVersion The major column value of the result is the version of your PowerShell....