0

The problem is with loop DoUntil. The script must take the URL, than ask what to do with him and gave the result after the user pick the number(1-4) and with output give the menu again, and user can pick another number if he want or finish the script typing 'X'.

But this script works in a different way, it is ask for URL, after I will pick the number, and after this it asks again the URL and again the number and after this(if for example I will pick twice the same number) it will bring me the value of 2 URLs together.

Please, advice, what I'm doing wrong.

write-host ""
write-host "Past URL that you need to check"
write-host ""
write-host -nonewline "Type your URL and press Enter: "
$URLok = read-host
write-host ""

if ($URLok.Length -lt 1) {
    write-host "Invalid selection"
}

do {
    write-host "What do you want to do with this URL?"
    write-host ""
    write-host "DNS - Selection 1"
    write-host " MX - Selection 2"
    write-host " NS - Selection 3"
    write-host "TXT - Selection 4"
    write-host ""
    write-host "X - Exit"
    write-host ""
    write-host -nonewline "Type your choice and press Enter: "

    $choice = read-host

    $ok = $choice -match '^[1234x]+$'

    if ( -not $ok) {
        write-host "Invalid selection"
    }

    switch -Regex ( $choice ) {
        "1"
        {
            [System.Net.Dns]::resolve($URLok)
        }

        "2"
        {
            Resolve-DnsName -Name $URLok -Type MX -DnsOnly | select Name,Type,NameExchange
        }

        "3"
        {
            Resolve-DnsName -Name '888ladies.com' -Type NS -DnsOnly | select Name,Type,NameHost,PrimaryServer

        }

        "4"
        {
            Resolve-DnsName -Name $URLok -Type TXT | select Name,Type,Strings
        }

        "5"
        {
            write-host ""
            write-host "Past URL that you need to check"
            write-host ""
            write-host -nonewline "Type your URL and press Enter: "
            $URLok = read-host
            write-host ""
        }
    }
} while($choice -ne "X")

P.s. And Little remark, in the 2-3-4 options I have 'Resolve-DNSName' but this script wouldn't show it on the console before the loop doUntil finished. So I can see the result only if I pick 'X' and finish the loop

Paxz
  • 2,959
  • 1
  • 20
  • 34
  • The main problem is with output on options 2-4, because if I put Write-Host, it will gave me not table with columns, it would be one big string –  Sep 24 '18 at 13:40

1 Answers1

0

The answer was with the pip Format-Table and it's work!

For Example:

Resolve-DnsName -Name $URLok -Type NS -DnsOnly | select Name,Type,NameHost,PrimaryServer| Format-Table