Powershell Script to get list of primary domain and IP address

Hi, I need a script which can get the top-level domain and URL which has IP address.

I have a text file with following url


After putting the file through a script the list should look like this


What have you tried? Do you have any code to start? I’m not aware of a script that would do this already (maybe try powershell gallery).

If you are trying to tackle this from scratch I would probably start by manipulating each string to split it up in its relevant parts i.e. -split “:” and -split “//” and -split “.”

Post back with some code, and I’ll do my best to help.

lol this is grep/regex
Assume you have a file named waffles.txt with:


grep -E -o “([0-9]{1,3}[.]){3}[0-9]{1,3}” waffles.txt
^This gets you the IPs

grep -Eo “[a-zA-Z0-9]+([-.]?[a-zA-Z0-9]+)*.[a-zA-Z]+” ./fox.txt
Is super messy but would get you domain names.

You just need to learn regex/grep and as Mike said split things between // and the following /

Good luck and have fun :wink: