Hi there people!
I am struggling with a “break of completing” in my foreach loop that scans websites for DNS information.
The aparrant reason for my issue, is that i call for an invoke-webrequest besides my resolve-dnsname call.
It seems, that if my invoke-webrequest cannot complete, then neither will the rest of the code, and i simply get empty outputs on Nameserver, MX records and so on.
I have tried for quite a while to figure out how to tell powershell to ignore if invoke-webrequest cannot be completed, but ive had no luck so far.
If i remove the section “$DomainFinal = (Invoke-WebRequest -Uri $DomainName********” the scan works well enough.
The reason for my invoke-webrequest, is in order to get the “final destination” of the call, to find if the websites redirects somewhere else, which is a function i would really like to keep. the Rmatch function just checks if the final destination matches the searched domain and returns false if not.
If the invoke-webrequest fails, all i get is "The remote server returned an error: (403) Forbidden. " and no other output.
Can anyone help me figure out, how to allow a false return on the invoke-webrequest, while still getting the rest of the available data?
A picture of an output:
The second last in the scan is the one failing, and returning ? and false on resolve, which is does not if the invoke-webrequest does not take place.
I really hope someone can help me out here!
Link to the script: