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

Select-String after line break

I want to extract the ID from this command: manage-bde -protectors c: -get The result of this command is: Volume C: [Windows] Tous les protecteurs de clés Mot de passe numérique : ID : {XXXXXXX-A315-42C6-9754-XXXXXXXXXX} …
Eglyn
  • 3
  • 1
0
votes
2 answers

PowerShell - carve out a part of the select-string output

I'm copying a large amount of data using AzCopy and I need to have a way to retrieve the files that failed to copy. AzCopy creates a nice log from each job and can do something like this: Select-String -Path…
0
votes
0 answers

Using Powershell, how can I parse an outlook attachment name and save it

I am new to Powershell (and coding in general) and am attempting to save outlook attachments that are all in the form of .xlsx from a specific sender. I managed to get a general script written to save attachments from the sender, but I also want to…
caweisz
  • 1
  • 3
0
votes
3 answers

How to use 'Select-String' to filter lines from an output

(first of all, I have searched SO,internet,youtube, for half an hour and didn't came with proper answer so I ask here) I'm coming from the realm of routers and helpesk when you can simply filter string\s from an output with "| include" (cisco) or "|…
Omer Meister
  • 43
  • 1
  • 8
0
votes
1 answer

Powershell Select-String

I need your help with PowerShell. I need Select-String with fixed Date (in variable). & Set-Content to result.txt Example: $Date = "01.07.2020" But also i need select string with date which lower than i written in variable. My code: Get-Content…
Karmanov
  • 3
  • 1
  • 2
0
votes
1 answer

Powershell parse unformatted text file

I am trying to parse a text file which is basically in a following format: Name: James Location: UK I think it makes most sense to use Select-String: $getName = "C:\account.txt" Select-String -Path $getName -Pattern 'Name: ' However, this…
cel09
  • 63
  • 3
  • 8
0
votes
1 answer

Get a string using Select-String method in Powershell

I have many text files like these and below is a sample from one such file. This is part of a file File_Content12. name:duplicate1-content:philips -sequence:primary........... name:guard1-content:sony…
Vignesh
  • 27
  • 1
  • 7
0
votes
2 answers

Powershell using Select-String gives no results

I have the following command Get-WindowsDriver -Online -All | where {$_.ClassName -like "Display"} This gives me the result like this Driver : vrd.inf OriginalFileName :…
MistyD
  • 16,373
  • 40
  • 138
  • 240
0
votes
1 answer

Powershell scripting - searching for string in files recursively using regex and outputting regex groups to file

I am recursively searching all files in a specified folder using regex. These are icons (fontawesome) that are being used and I want to create a list of each that I use in my project. They are in the format fa(l, r, s, d, or b) fa-(a-z and -). My…
user756659
  • 3,372
  • 13
  • 55
  • 110
0
votes
1 answer

How to search for a value in one long string?

I'm currently trying to filter a value from a long string I got by using a GET request with the cURL command. The output looks like…
0
votes
2 answers

Powershell extract log file content for last n minutes

I am trying to extract content from a log file for last n minutes and perform another set of actions based on the extracted data. My Log file look like below: 2019-01-25 02:45:55,018 [5 - -22d] INFO Server - Some information 2019-01-25 02:45:55,018…
ps2090
  • 223
  • 2
  • 15
0
votes
1 answer

how to find lines that match many patterns

I'm trying to find lines starting from one of many patterns in many files (log parsing). Is there any better solution than: Get-ChildItem -Filter *DBLog.txt | ForEach-Object { $name = $_.Name Get-Content -Path $_.FullName | …
0
votes
1 answer

How to "grep" in PowerShell one-liner?

What is the best short one-liner in PowerShell to use as a grep alternative? I wanted to share with you this short one-liner syntax for PowerShell version of grep, which perhaps is relatively little known.
Klaidonis
  • 559
  • 2
  • 6
  • 22
0
votes
2 answers

How can I write the output of Select-String in powershell without the line numbers?

I am using powershell to filter a textfile using a regular expression. To do that I am using the following command: Select-String -Pattern "^[0-9]{2}[A-Z]{2}[a-z]{5}" -CaseSensitive rockyou.txt > filter.txt The issue however, when writing them to…
ASlackjaw
  • 11
  • 1
  • 4
0
votes
1 answer

how to Filter the full Log context using PowerShell

I am trying to filter out the logs and its full context using Select-String in powershell. I know the parameters of context and their meanings but this limits to what I am trying to achieve. Below is the log snippet and I want to search the log with…