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.

I find using
type casting(if available) will help when working with some type of complex objects.So by comparing the property
AuthoritywithHost(in this case filtering), you can easily tell if the URL-file needs to be handled.In this case we also need a good way to handle ini-files.
PsInifromPSGalleryis a good bet.Edit: I didn't notice the property
IsDefaultPortbefore which makes to selection even easier.