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
1
vote
1 answer

Select-string multiple variable patterns

I am trying to extract error lines from a log file which are defined by two things. The log file line looks like this: 2018-05-22 06:25:35.309 +0200 (Production,S8320,DKMdczmpOXVJtYCSosPS6SfK8kGTSN1E,WwObvwqUw-0AAEnc-XsAAAPR) catalina-exec-12 :…
dkrizka
  • 13
  • 5
1
vote
3 answers

How to save select-string output from bulk text files to an array powershell

I am trying to pull substrings out of text files in bulk saving these substrings to an array. I have tried variations of the following. This outputs all of the selected strings to the screen but only saves the final output to the variable. Is there…
Merrill Cook
  • 988
  • 1
  • 8
  • 18
1
vote
1 answer

select-string stuck in endless loop

I am trying to extract all text matching a particular pattern from files in the directory using PowerShell. However, for some reason it seems to loop indefinitely (output is an endlessly repeating set of the same results and the script never…
Daria Da
  • 19
  • 2
1
vote
2 answers

Powershell - Sorting and selecting files in foreach loop

I'm trying to create a script that will find the most recent build_info files from multiple install locations in a server's directory, select the "version: " text from each file, and compare them to see if they're all the same (which is what we hope…
1
vote
1 answer

How do I get the full output of a command while using "findstr"?

I am trying to get the full output of the command netstat -abn while using Select-String or findstr but it's not working since only the search string is being listed. I am looking the same behavior as grep does on Linux where if you run netstat -an…
ReynierPM
  • 17,594
  • 53
  • 193
  • 363
1
vote
3 answers

Select-String cmdlet in PowerShell. Parsing parenthesis

I have this stored in a text file shown below: Java 8 Update 111 Java 8 Update 111 (64-bit) Java 8 Update 131 Java 8 Update 151 Java 8 Update 152 I am using PowerShell to do something with this information but struggling at the first hurdle. I am…
d4rkcell
  • 147
  • 3
  • 4
  • 11
1
vote
1 answer

Powershell Select-String list multiple matches

I'm trying to do some pattern-matching based a list of words against some XML files. I have the following: $Result = Get-ChildItem -Recurse $FullPath\*.xml | Select-String -Pattern $WordList | Select-Object Path, Pattern, Line, LineNumber My…
JohD
  • 25
  • 1
  • 4
1
vote
1 answer

Select-String fails with search term containing special characters

When I run: $SearchStr = "c:\programFiles\xyz" Select-String -pattern $SearchStr -path $env:SystemRoot\win.ini I get an error message stating that the string is "not a valid regular expression" By contrast, it is working fine when $SearchStr…
Allforone
  • 84
  • 2
  • 10
1
vote
1 answer

Select-String issue working intermittently

I have some code that works sometimes and others not. I see no errors when it fails so I am stuck as to why its intermittent. I am using the Select-String cmdlet which will find many matches which is what I want. I am also using the same text file…
LDStewart
  • 117
  • 3
  • 11
1
vote
1 answer

Finding multiple strings on the same line in text files with PowerShell Select-String

I'm trying to find all the SQL Server object names (roughly 800) in our source controlled files (1000's.) When I try using Select-String it will find one string but then it stops processing the file on the line it found a match. Here is a small…
runamuk0
  • 784
  • 1
  • 7
  • 20
1
vote
2 answers

Powershell to Extract String after finding another string

I'm looking for a way to find a string in a file, then extract everything between that string and a separator. I can get the LINE out of the file, but I'm a little stumped on how to get the string I want out of it. Line out of the file is…
TheDoc
  • 688
  • 2
  • 14
  • 33
1
vote
2 answers

PowerShell Remove path from Select-String Output using a variable

First of all, I want to apologize. I do not work with Powershell. This was a great learning experience for me! If my code makes you cringe, I am sorry :) I work with multiple buildings, Sometimes it is difficult to tell where a user is and it…
1
vote
4 answers

Tailoring select-string output.

I have a text file log that looks like this 2 total number of add errors I have a script that is get-content "c:\logfile.txt | select-string "total number of add errors" I cant remember how to get it to just show the number. Any suggestions?
StrawDogz
  • 23
  • 1
  • 5
1
vote
2 answers

PowerShell Boolean Expression

I am writing a powershell script but having a problem evaluating a boolean expression. This is the line of code I am having a problem with: if (Get-Content .\Process2Periods.xmla | Select-String ((Get-Date) | Get-Date -Format "yyyyMM") -quiet -ne…
1
vote
1 answer

Powershell - Select-String -Quiet not working as intended?

So I am writing a powershell script that, among other things, checks to see if you are in an Exchange Distribution Group, and adds you if necessary. One thing that is making it tricky is, the script is getting its data from an "unreliable" source.…
romellem
  • 5,792
  • 1
  • 32
  • 64