Checking for present variables (invoke-webrequest)

Hi there people!

I am trying to make Powershell check for several values for me, during an Invoke-Webrequest

I am struggling a bit with how to “tell me which one” it finds, instead of just giving me “true / false”

Im pretty sure this could be done in many smarter ways, but this is just a small thing i need to check through some values :slight_smile:

My miniature script looks like this right now:

$Site = ""
$Request = (Invoke-WebRequest -URI $Site)

$substrings = $Request.substring

If (($substrings) -match '4160' -or '9956' -or '1253')

write-host "Match found"

#How do i output the specific one of these two that matches?
# i would love to simply get the output 4160, if the substring 4160 is found.




write-host "no matches found"


Best regards
Jonatan Nielsen

A little note of progress:

I have now made this script work with getting all the “4 digit numbers” from the site, working on “validating them” now

$Site =
$Request = Invoke-WebRequest -URI $Site

$fourdigitvalues = ($Request | Select-String -Pattern "(?<!\d)(\d{4})(?!\d)" -AllMatches).Matches

foreach ($individualfourdigit in $fourdigitvalues) {

write-host $individualfourdigit }

I think you make your life harder than needed. Usually PowerShell tries to make it easier for you.
When you run the code above you have an obejct with properties you can work with. To see the properties you simply output the complete object by calling the variable


From there you continue to pick whatever property you’re after and do all further steps needed.

Hi Olaf!

Thanks for your assistance here :slight_smile:
I managed to make it work!

I ended up “validating” the 4 digits found, by matching their city name, and then looking for the existence of that name.
If both the number and its corresponding city was present on the site, it was verified and put out as the location of the company :slight_smile: