Questions tagged [select-string]

Select-String is a powershell cmdlet that finds text in strings and files.

Select-String is a powershell cmdlet that finds text in strings and files.

The Select-String cmdlet searches for text and text patterns in input strings and files. You can use it like Grep in UNIX and Findstr in Windows. You can type "Select-String" or its alias, "sls".

Select-String is based on lines of text. By default, Select-String finds the first match in each line and, for each match, it displays the file name, line number, and all text in the line containing the match. However, you can direct it to detect multiple matches per line, display text before and after the match, or display only a Boolean value (true or false) that indicates whether a match is found.

Select-String uses regular expression matching, but it can also perform a simple match that searches the input for the text that you specify.

Select-String can display all of the text matches or stop after the first match in each input file. It can also display all text that does not match the specified pattern. You can also specify that Select-String should expect a particular character encoding, such as when you are searching files of Unicode text.

230 questions
0
votes
1 answer

Selection for strings with escaping characters

The following code, somehow, does what I want, except for certain lines that contain \ and another problem. I'd like to clear up first the inconvenient concerning the defective selection for strings containing \. $FC=(gc…
LPH
  • 153
  • 1
  • 10
0
votes
1 answer

Powershell - Select-String Advice needed

My goal is to create a PS script that does the following: a) scans a source directory and produces a list of files that have a matching pattern that I pass in found inside the files b) take the list of those files and Copy-Item to move and then…
0
votes
1 answer

Can I have two "tail"s in one logfile within a while loop that one condition does one thing and the other does something else?

I have a script that is supposed to look at a logfile that starts filling with several hundred lines. While the log is filling, I need to look for two different conditions at the same time. If I find "Completed Successfully" then it will break the…
0
votes
1 answer

Trouble accessing members of select-string output when input is a system.array

I am calling restAPIs and some of them return multiple results, I am trying use Select-String to get the correct line in the Array, but it returns a matchinfo object with a value starting with @{... I can't get this value into a hashtable or object…
fsher
  • 33
  • 5
0
votes
1 answer

Search HTML Data Retrieved from Invoke-WebRequest with Regex

I am trying to scrape data from https://www.reuters.com/finance/stocks/lookup?searchType=any&comSortBy=marketcap&sortBy=&dateRange=&search=Accor. The end goal is to pull the table down that contains the Company, Symbol and Exchange. I have…
0
votes
2 answers

How to match 3 lines in txt file and extract string in the middle line

Using Powershell I would like to extract a value from text file that is in between two lines that match a pattern. I'm trying to match 3 lines, 1st & 3rd will always be the same: 1st: ' 1' 2nd: trying to read... always 2-4 characters 3rd: '…
0
votes
3 answers

Searching for literal string with Select-String and extracting part of string

The value of $DeviceID is : "PCI\VEN_8086&DEV_9D3A&SUBSYS_225617AA&REV_21\3&11583659&1&B0" I'm trying to search for that string in .INF files with "Select-String" : Select-String -Path C:\file.inf -Pattern "$DeviceID" But it won't take the string…
Rakha
  • 1,874
  • 3
  • 26
  • 60
0
votes
1 answer

Include the text line before the specified filter select-string or findstr

PS C:\Windows\system32> nmap -sP 10.0.1.0/24 Starting Nmap 7.70 ( https://nmap.org ) at 2019-04-30 13:13 Vest-Europa (sommertid) Nmap scan report for 10.0.1.1 Host is up (0.12s latency). MAC Address: 90:72:40:04:F7:85 (Apple) Nmap scan report for…
0
votes
2 answers

Why doesn't Select-String filter the input of a ToString() method?

Why doesn't powershell filter the output of an object's toString method? Get-ChildItem cert:\localmachine\my | % { Select-String -InputObject $_.ToString() -Pattern 'testcert' -SimpleMatch } Instead I just get everything I would normally get by…
leeand00
  • 25,510
  • 39
  • 140
  • 297
0
votes
1 answer

Blank first line when using "select-string -pattern" to strip lines from file

I have a simple text file that looks like this... A,400000051115,null,null,null,null,null,null,null,20190312,090300,Answer…
0
votes
2 answers

searching a log in powershell

I'm trying to use powershell to search a log for a particular string - and then use a particular section of a line that has that string. The log lines I'm interested in look something like this: 2019-02-25 11:51:37.394…
Josh Nelson
  • 49
  • 2
  • 7
0
votes
1 answer

PowerShell Split Select String

I have the following command Get-ChildItem -Recurse -Path 'C:\root' | Select-String -Pattern '172\.20\.' | group | select name | export-csv -Path 'C:\test.csv' This command goes through .zone files and returns the path of the file and the string…
user3127554
  • 521
  • 1
  • 7
  • 28
0
votes
1 answer

running PowerShell cmd with pipeline in cmd prompt

I want to run the cmd select-string in cmd prompt to find some string recursive. But it can't work while the cmd have the pipeline(|) character, and it will work by running the cmd in the powershell prompt. The Chinese error info…
Victor Lee
  • 2,467
  • 3
  • 19
  • 37
0
votes
1 answer

Powershell doesn't show result exactly (ip address)

i try to get just 1.1.2.1 but it shows me other ip too my test code is $reader = @([System.IO.File]::ReadAllLines("c:\test2.log")) |select-string "1.1.2.1" $reader = [System.IO.File]::ReadAllLines("c:\test2.log") |select-string "1.1.2.1" $reader =…
Angel Cha
  • 1
  • 2
0
votes
1 answer

Grep on Windows for pptx files

I have a directory full of powerpoint presentations(pptx). I'm trying to find the presentations that have the word "December" in them. In my Mac I could use grep, but in Windows I've been trying to use Powershell and the command prompt and it is not…
user9221735