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

How do I select multiple columns and expand properties using powershell select-string -Allmatch?

I'm searching a collection of text files (*.sql) for the occurrence of 8 digit numbers that begin with a 9. There could be multiple instances of these numbers in the file as well as multiple instances on each line in the file. I only want the…
RayBan
  • 13
  • 1
  • 1
  • 3
1
vote
0 answers

Fail to use select-string -context in Powershell

I am trying to extract information through an HTML text which I retrieved from a web site page by means of powershell. Here is the sample text:
mlee_jordan
  • 772
  • 4
  • 18
  • 50
1
vote
3 answers

How to get just the part around regex using powershell select string?

I use select-string from powershell and it works nice, but sometimes I dont like that it gives me the entire line that matched because it contains (for me) unnecessary information. Is there simple way to have it give me just 10 chars before regex,…
NoSenseEtAl
  • 28,205
  • 28
  • 128
  • 277
0
votes
1 answer

Why this Powershell Regex for serial numbers returns everything with Select-String?

I'm trying to get the first serial number of Chromedriver from this string in Powershell with Select-String, but the regex returns everything: '\d{1,4}.\d{1,4}.\d{1,4}.\d{1,4}'. The regex works well in regex101 and regexr and I've been checking…
Noob_Number_1
  • 725
  • 5
  • 20
0
votes
1 answer

How do I add a substring from a filename into a CSV with the file's properties?

Evening everyone, I'm currently working on a script intended to check the last modified time of .docx files in multiple subdirectories and then export the file name, path, modified date, and a substring from the filename into an Excel. The idea is…
0
votes
2 answers

Look for files with today's date and look for pattern in file, print what found

I'm trying to find the powershell equivalent of this Windows shell command, except now I'm looking for files with today's date: findstr /S /C:"Firmware version text" C:\Temp\Filename1* & findstr /S /C:"Class::Method1" C:\Temp\Filename1* & echo…
Michele
  • 3,617
  • 12
  • 47
  • 81
0
votes
1 answer

Exact match using Powershell from a string variable

I have tried applications applications of Select-String or -match etc to get what I need. It is just not happening. Using the string as examples.. I am searching a text file so I can then grab to the ed of the line for each match so I can save…
MikeC
  • 37
  • 6
0
votes
1 answer

How can I split the result of powershell select-string command?

I have a command like this: powershell -command "Select-String -Path 'C:\Program Files\Zabbix Agent 2\zabbix_agent2.conf' -Pattern 'ServerActive'" Which outputs: C:\Program Files\Zabbix Agent 2\zabbix_agent2.conf:5:ServerActive=79.240.122.98 I want…
Bajuldi
  • 35
  • 4
0
votes
0 answers

Replacing a keyword in a .txt file. Poweshell Scripting

I'm trying to replace a keyword in a .txt file, but nothing happens and the .txt file remains the same. The keyword im trying to replace is "dataSource.password". I'm trying to use -replace and Foreach-Object on replacing certain keywords Here's the…
Miggy
  • 3
  • 2
0
votes
0 answers

Powershell | Select-String multiple lines regex pattern filters nothing

The situation I have a string like this: some-text some-other-text From which I want to get only what's commented, so like this: What I've tried I read similar…
Bit
  • 21
  • 7
0
votes
1 answer

select-string in powershell like operation in python

Is there anything which gets the lines of given pattern in python like we have in powershell $Response2.RawContent -split "`n" | Select-String $ans -Context 1,4 in powershell it is getting 1 line before and 4 lines after the line in which matched…
0
votes
1 answer

Search for and combine two fields in a csv with powershell

I want to search for a string in every file in the current directory, combine the results, and output a text file. The string that I'm looking for is "Start l". This will return two results, "Start latitude" and "Start longitude". I want to combine…
Sam Alleman
  • 141
  • 7
0
votes
2 answers

select-string with multiple conditions with powershell

I'm looking for a way to find 2 different lines in a file and only if those 2 line exist I need to perform a task. So far this is my code $folderPath = c:\test $files = Get-ChildItem $Folderpath -Filter *.txt $find = 'stringA' $find2 =…
Eran Avni
  • 25
  • 1
  • 7
0
votes
1 answer

Powershell - Search for Pattern and Copy

i have a bunch of *.CSV Files. Huge *.CSV Files. I try to search for a specific pattern in these Files called "Secure". If found, the script shall copy it to a folder. It works, but it has one Problem i could'nt solve. In some files, the Word i'm…
rzhell
  • 35
  • 5
0
votes
2 answers

I need my Get-ChildItem string search command print file names along with their Date Modified values, sorted

I spent quite some time searching for the solution of my problem, but found nothing. I have one single folder with mostly .html files, and I frequently need to search to find the files that contain certain strings. I need the search result to be…