Skip to main content

All Questions

4 votes
2 answers
168 views

Select-String: match a string only if it isn't preceded by * character

I have this line in a Powershell script: if (Select-String -Path "$holidays" -Pattern "(?<!\*)$datestr" -SimpleMatch -Quiet) $holidays is a text file where i have some date: ...
Fryc's user avatar
  • 143
0 votes
1 answer
55 views

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 ...
Noob_Number_1's user avatar
0 votes
0 answers
30 views

Powershell | Select-String multiple lines regex pattern filters nothing [duplicate]

The situation I have a string like this: some-text <!-- <div class=""> </div> --> some-other-text From which I want to get only what's commented, so like this: &...
Bit's user avatar
  • 21
3 votes
1 answer
822 views

Powershell/Regex to count number of times a date range appears

I am working on a script to pull metrics from a log file. Here is an example from the log. 2/21/2022 3:29 PM: Requested username - Found disabled account with matching CATIID named username - Account ...
Rich's user avatar
  • 57
1 vote
1 answer
614 views

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:.*...
leeand00's user avatar
  • 26.5k
1 vote
2 answers
400 views

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 ...
Indiana Indy Jones's user avatar
0 votes
1 answer
887 views

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 ...
freakostudent's user avatar
2 votes
1 answer
1k views

How to Select-String from Multiple Lines with Powershell

I have this file below test.dat <category>Games</category> </game> <category>Applications</category> </game> <category>Demos</...
volitank's user avatar
0 votes
2 answers
45 views

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....
vespavbb's user avatar
1 vote
2 answers
244 views

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' ...
Nicholas Saunders's user avatar
0 votes
2 answers
3k views

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 "*....
dbutts's user avatar
  • 43
0 votes
0 answers
605 views

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 ...
caweisz's user avatar
0 votes
1 answer
618 views

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 ...
Klaidonis's user avatar
  • 639
1 vote
2 answers
2k views

Search regex pattern with PowerShell and output filename

$input_path = "d:\txt\*.txt" $output_file = 'd:\out.txt' $regex = "\w* (\w\.? )?\w* (was )?[B|b]orn .{100}" select-string -Path $input_path -Pattern $regex -AllMatches | % { $_.Matches } | % { $_....
Stphn's user avatar
  • 117
1 vote
2 answers
352 views

Powershell Regex Complex Pattern (XML)

I have a string in an XML which I am trying to retrun to a varable (below). <XMLElement><![CDATA[TEXT - I - FIND - INTERESTING]]></XMLElement> My problem is that I have no knowledge ...
Reg's user avatar
  • 13

15 30 50 per page