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
0 answers

Need PowerShell help using Select-String to match text in a file with a wildcard

I am having trouble figuring out how to match the text with wildcards. The script works for finding ServerName= but I can't figure out how to find ServerName=GSW-ACE-01 The text after the equal sign is different so I need a wildcard to pull all…
PapaDoc
  • 11
  • 1
1
vote
1 answer

Script lists all files that don't contain needed content

I'm trying to find all files in a dir, modified within the last 4 hours, that contain a string. I can't have the output show files that don't contain needed content. How do I change this so it only lists the filename and content found that matches…
Michele
  • 3,617
  • 12
  • 47
  • 81
1
vote
1 answer

Select-String regex for multiple strings

I am trying to extract last entry from an curl output to only show me the plugin-name and version. Unfortunately miserably failing with my command. Here is the command being used at my end curl --silent…
Rohit
  • 245
  • 1
  • 2
  • 6
1
vote
1 answer

Powershell Select-String Problem with variable

I have a CSV list of numbers that I would like to use Select-String to return the name of the file that the string is in. When I do this $InvoiceList = Import-CSV "C:\invoiceList.csv" Foreach ($invoice in $InvoiceList) { …
Jeff Ku
  • 13
  • 3
1
vote
2 answers

How can i search for multiple string patterns in text files within a directory

I have a textbox that takes an input and searches a drive. Drive for example is C:/users/me let's say I have multiple files and subdirectories in there and I would like to search if the following strings exist in the file: "ssn" and "DOB" Once user…
Richard Jimenez
  • 177
  • 1
  • 1
  • 11
1
vote
1 answer

Powershell select-string match first instance in file and output filename

I have a number of Log files that are generated by an IMAPSync process. There is a Log file per mailbox that has been synced. I need to identify all the log files that have a specific string. Currently I have Get-ChildItem -Filter *.txt |…
TheDemonLord
  • 327
  • 1
  • 2
  • 15
1
vote
2 answers

powershell select-string -pattern -path finds hits where there are none

I´d like to use PS to scan some log files for errors select-string -pattern '[E]' -path D:\15\s\BAS\VectorNetworkAnalysis.AutomationInterfaceTests\Tests\COMTesting\PythonUnitTests\PyTestsResult*.log but despite there are NO ERRORS PS lists every…
AlexxRR
  • 11
  • 2
1
vote
1 answer

Matching an unknown number of multi-lines an unknown number of lines with Select-String in Powershell?

I've been able to match multiple lines; but only if I know how many lines are coming, and what the content of those lines are... Select-String -Pattern "^Timestamp: 3/27/2021.*`n`n|^Message:.*errorText:" -Context 2 -LiteralPath .\SomeLog.log Is…
leeand00
  • 25,510
  • 39
  • 140
  • 297
1
vote
1 answer

how to extract specific line after matched line in select-string powershell

I want to search for text in a block or rather after the matched string but not immediately e.g: From output of 'ipconfig', I wanna extract the IPv4 address in WiFi section only ipconfig | sls -Pattern "Wifi" -Context 0, 4 returns matched string…
SEKTION
  • 87
  • 9
1
vote
1 answer

PowerShell search for multiple strings on one line

Spent a few days going through a few dozen examples but, unfortunately, not found a solution yet. Hoping you guys can help. I need to search a bunch of log files at once and on each line check today's date and for a specific string - and…
Nimster
  • 21
  • 1
1
vote
2 answers

Return boolean from string search

I'm trying to return TRUE from searching Get-ComplianceSearch's output for 'Completed'. My code below is a simple wait loop. But I don't think I'm returning the value correctly because the loop never finishes. I'm fairly new to PowerShell. Please…
Ccorock
  • 892
  • 12
  • 37
1
vote
2 answers

Using regex within text with carriage return

I'm using a regex in a txt using powershell, but it's work only if the text doesn't contain carriage return. I prepared an example file like this: the duck is on the table --found! the elephant is on the table --found! the cat is on the…
1
vote
1 answer

How can I grep for a String in a powershell output using "|"?

It seems like in powershell, echo ASDF | Select-String ASDF outputs the obvious string, ASDF. However, if i attempt to look at WinEvents, and look for an output, i.e. Get-WinEvent -ListLog * | Select-String antrea It seems as if the raw text is…
jayunit100
  • 17,388
  • 22
  • 92
  • 167
1
vote
2 answers

Use Powershell to match and print specific column from output

I want to fetch a specific column from an output of a command. Can someone please suggest what is the best way to do it? The command used is - choco list -lo which gives the output as Chocolatey v0.10.15 chocolatey 0.10.15 erlang 22.3 rabbitmq…
Ismail
  • 779
  • 1
  • 8
  • 18
1
vote
2 answers

How to match for "foo" and "bar" with Select-String in Powershell?

How to get the result of these Select-String matches in one statement? posh> posh> $string = Get-Content /home/nicholas/powershell/regex/text.txt posh> $patternFoo = 'foo' posh> $patternBar = 'bar' posh>…