问题在于循环 DoUntil。脚本必须获取 URL,然后询问如何处理他并在用户选择数字(1-4)后给出结果,然后输出再次给出菜单,用户可以根据需要选择另一个数字或完成脚本输入“X”。
但是这个脚本以不同的方式工作,它是询问 URL,在我选择号码之后,然后它再次询问 URL 和号码,然后(例如,如果我将选择两次相同的号码)它将为我带来 2 个 URL 的值。
请指教,我做错了什么。
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")
Ps 和一点评论,在 2-3-4 选项中我有 ' Resolve-DNSName
' 但是这个脚本不会在循环doUntil
完成之前在控制台上显示它。所以只有当我选择'X'并完成循环时我才能看到结果