- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to search in the file using PowerShell?
To search the content in the file in PowerShell, you need to first get the content from the file using Get-Content command and then you need to add Select-String pipeline command. In the below example, we need to search the lines which contain the Get word.
PS C:\WINDOWS\system32> Get-Content D:\Temp\PowerShellaliases.txt | Select-String -Pattern Get Alias cat -> Get-Content Alias dir -> Get-ChildItem Alias gal -> Get-Alias Alias gbp -> Get-PSBreakpoint Alias gc -> Get-Content Alias gcb -> Get-Clipboard 3.1.0.0 Microsoft.PowerShell.Management Alias gci -> Get-ChildItem Alias gcm -> Get-Command Alias gcs -> Get-PSCallStack Alias gdr -> Get-PSDrive Alias ghy -> Get-History Alias gi -> Get-Item Alias gin -> Get-ComputerInfo 3.1.0.0 Microsoft.PowerShell.Management Alias gjb -> Get-Job Alias gl -> Get-Location Alias gm -> Get-Member Alias gmo -> Get-Module Alias gp -> Get-ItemProperty Alias gps -> Get-Process Alias gpv -> Get-ItemPropertyValue
You can use multiple patterns to search for the result.
Example
Get-Content D:\Temp\PowerShellaliases.txt | Select-String -Pattern Get,Set
Output
Get-Content D:\Temp\PowerShellaliases.txt | Select-String -Pattern Get,Set Alias gsnp -> Get-PSSnapin Alias gsv -> Get-Service Alias gtz -> Get-TimeZone Alias gu -> Get-Unique Alias gv -> Get-Variable Alias gwmi -> Get-WmiObject Alias h -> Get-History Alias history -> Get-History Alias ls -> Get-ChildItem Alias ps -> Get-Process Alias pwd -> Get-Location Alias sal -> Set-Alias Alias sbp -> Set-PSBreakpoint Alias sc -> Set-Content Alias scb -> Set-Clipboard Alias set -> Set-Variable Alias si -> Set-Item Alias sl -> Set-Location Alias sp -> Set-ItemProperty Alias stz -> Set-TimeZone
- Related Articles
- How to install MSI file using batch file in PowerShell?
- How to edit the CSV file using PowerShell?
- How to mount the ISO file using PowerShell?
- How to dismount the ISO file using PowerShell?
- How to install the MSI file using PowerShell?
- How to get the file extension using PowerShell?
- How to convert JSON file to CSV file using PowerShell?
- How to search for files using the wildcard character (*) in PowerShell?
- How to read the windows host file using PowerShell?
- How to delete all the file contents using PowerShell?
- How to retrieve CSV file headers using PowerShell?
- How to create a temporary file using PowerShell?
- How to add the entry in the windows host file using PowerShell?
- How to check if the file is empty using PowerShell?
- How to update the windows host file entry using PowerShell?

Advertisements