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

How to find a word/phrase in a line using PowerShell?

I have been at this for days now but can't seem to figure it out. I am trying to compare values(PartNumber) from the database to the first line of the text file. If the PartNumber exists(in the first line of the file) display a message "Part Number…
Brute
  • 121
  • 1
  • 10
0
votes
0 answers

Select-String modification to remove truncation (and expand the property) in Line Object

I am a novice and have been tasked to extract data from a bunch of text files. I have managed to put together some very simple PowerShell code (seen below) that does most of the work. However, the Line object is truncated in the output file and I…
Adrian
  • 1
0
votes
0 answers

Powershell Script Outputs Unwanted References to Text File

My script finds a pattern and outputs all lines up to the pattern line into output.txt. But I get these added references in my output file when all I want is my original text. readfile.txt:2: readfile.txt:3:Original text in readfile.txt …
Dave
  • 687
  • 7
  • 15
0
votes
1 answer

How to get actual separate lines in PowerShell's Write-Output using a newline character

I tried to create a multiline Input to practice Select-String, expecting only a single matching line to be output, like I would normaly see it in an echo -e ... | grep combination. But the following command still gives me both lines. It seems to be…
Martin
  • 493
  • 6
  • 16
0
votes
1 answer

Powershell question - How can I deleted lines from a certain position?

(Sorry in advance for my bad english.) I have 2 questions: Question: I have a .txt file and search with powershell for a word into the .txt: My code: Select-String .\example.txt -pattern "myword" | select -ExpandProperty line OK nice. PowerShell…
0
votes
2 answers

Powershell Select-String not finding what I expect

I am trying to parse file paths to just get the file name and I have a regex .*\ I'll use the following Select-String -Pattern '.*\\' -InputObject $test -NotMatch on a file path like C:\Users\User\Desktop\test.exe and it returns blank. If I remove…
Eric Goto
  • 63
  • 8
0
votes
1 answer

Why sometimes powershell cmdlet "select-string" does not return any value?

This command works, logfolder contains several log files, select-string will search on each file and look for the -pattern 'update' get-childitem -recurse C:\logfolder -file | select-string -pattern "update" But this other line won't work, it won't…
darko
  • 23
  • 4
0
votes
1 answer

Powershell extract data from really weird JSON file

I have a really weird json file and I am trying to extract data from it via powershell. The issue is that the creator of this file is using json in a way I have never seen before: (Cities are not in the Array, Continents are not in the array…
aster007
  • 335
  • 2
  • 13
0
votes
1 answer

powershell | select-string pattern + line unter the pattern

is there a way to select a string pattern, and get also the line after the pattern. my metadata look like : "t": "d", "n": "00001212", "22.06.2031", "", "", "batman", my codeline looks like: $contentNameFolder=…
du7ri
  • 67
  • 1
  • 10
0
votes
1 answer

select-string, search one value, then if found search for a second. If both are found store the result

I'm trying to find a out when a series of values are present in a text file. Search value one will always be at least one line above search value two. However, it could be 20 lines down, or not exist at all. Every version of regex I attempt returns…
freakostudent
  • 105
  • 1
  • 2
  • 9
0
votes
2 answers

search for certian words in a string

I´m struggling in a simple report script. for example $report.FullFormattedMessage = "This is the deployment test for Servername for Stackoverflow in datacenter onTV" $report.FullFormattedMessage.GetType() IsPublic IsSerial Name …
vespavbb
  • 27
  • 2
  • 9
0
votes
3 answers

how to expand multiple properties when output contains @{, }?

I know there's a number of posts about expanding a single property and hopefully this is an easy one but my output looks like this as a result of a select-string -simplematch @{Brand=Volkswagen; Model=Passat} @{Brand=Ford; Model=Mondeo} But how do…
kkp0897
  • 19
  • 1
  • 1
0
votes
2 answers

Powershell - Finding the output of get-contents and searching for all occurrences in another file using wild cards

I'm trying to get the output of two separate files although I'm stuck on the wild card or contains select-string search from file A (Names) in file B (name-rank). The contents of file A is: adam george william assa kate mark The contents of file B…
kkp0897
  • 19
  • 1
  • 1
0
votes
1 answer

Why doesn't Find-String work on the output from Powershell commands?

I don't know if this is a problem on a larger set of Powershell library commands, but I'm using the Share Point Online library right now and can't get this to work: Get-SPODeletedSite | Select-String "100060-24" I can see that this string exists in…
Quark Soup
  • 4,272
  • 3
  • 42
  • 74
0
votes
2 answers

Select-string regex

I'm searching a ton of logs using a foreach loop for a string ($text) and currently outputting the entire line to an output file ($logfile) Get-ChildItem "\\$server\$Path" -Filter "*.log" |select-string -pattern $text |select -expandproperty line…
dbutts
  • 17
  • 7