Building on the code from this answer, I tried this to find all .url files which include http://kfhntwvap347, but I also tried http://kfhntwvap347:8080/consense/ in $urlParts knowing that there is such a .url file, but it always shows no results.
The intent is to find such URL and then to replace it.
# The literal URL parts to find, either prefixes or substrings.
$urlParts = 'http://kfhntwvap347'
$regex = '^URL=({0})' -f (
$urlParts.ForEach({
$escaped = [regex]::Escape($_) # Escape for literal matching, if needed.
if ($escaped -match '^https?:') { $escaped }
else { '.*' + $escaped } # match anywhere in the URL
}) -join '|'
)
# Search all *.url files in the subtree of D:\waveprod\DMS for the URL parts
# and output the full paths of matching files.
# Outputs to the screen and saves to a file.
$foundPaths = Get-ChildItem -Force -Recurse D:\waveprod\DMS -Filter *.url |
Select-String -Pattern $regex -List |
ForEach-Object {
$path = $_.Path
Write-Output $path
$path
}
# Display a message based on whether results were found or not
if ($foundPaths.Count -gt 0) {
Write-Host "Results found!"
} else {
Write-Host "No results found."
}
# Save the found paths to a text file in D:\powershell\
$foundPaths | Out-File -FilePath 'D:\powershell\found_paths.txt'
I would expect that it finds such files but I tried many variations without success.

$urlParts = 'http://kfhntwvap347', the code does match a.urlfile with the content shown in your screenshot in my tests. Please try to provide a minimal reproducible example.ifstatement, you're checking if it matches^http?:'. This regex matches eitherhttp:orhtt:. I'm assuming what you want is^https?:, which matcheshttp:orhttps:. Also in yourForEachloop you output the$pathtwice and also assigning$_.pathto$pathis unnecessary, just use this:ForEach-Object { $_.path }^http?:part to avoid confusion: It was simply a copy-paste error from the linked answer.(New-Object -ComObject WScript.Shell).CreateShortcut("d:\path\to\some.url").TargetPathto more robustly extract the URL string). The linked post (to which this question is a follow-up) makes the use case clearer: matching one of multiple arbitrary URL prefixes and substrings, for which text processing is the right approach, and regexes allow for the most concise implementation.