This should work.
foreach ($w in $wmi) { if ($w -Like "10.64*") { $w } }
--
John Wright
IT Support Specialist
![]()
1800 Old Bluegrass Avenue, Louisville, KY 40215
Please submit IT requests to Hazelwoo...@newvista.org
24 Hour Helpline 1.800.928.8000
CONFIDENTIALITY NOTICE: This message contains confidential information and is intended only for the individual(s) addressed in the message. If you are not the named addressee, you should not disseminate, distribute, or copy this e-mail. If you are not the intended recipient, you are notified that disclosing, distributing, or copying this e-mail is strictly prohibited.
From: ntpowe...@googlegroups.com <ntpowe...@googlegroups.com>
On Behalf Of Mike Leone
Sent: Tuesday, February 21, 2023 12:50 PM
To: NTPowershell Mailing List <ntpowe...@googlegroups.com>
Subject: [ntpowershell] How best to retrieve IPv4 (only) addresses from remote computers
|
This message is from an external sender. |
--
You received this message because you are subscribed to the Google Groups "ntpowershell" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
ntpowershell...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ntpowershell/CAHBr%2B%2BhYae%3DutzJ7W7mW7KCfUNiiOo_uu2QJteLCt4uWZOJT3A%40mail.gmail.com.
|
[CAUTION] Do not click on links or open attachments unless you recognize the sender and know the content is safe. |
Try this:
$NAAdptr = Get-NetIPAddress -AddressFamily IPv4 | Where-Object {$_.IPAddress -like '10.64.*'}
Gordon
From: ntpowe...@googlegroups.com <ntpowe...@googlegroups.com>
On Behalf Of Mike Leone
Sent: Tuesday, February 21, 2023 10:50
To: NTPowershell Mailing List <ntpowe...@googlegroups.com>
Subject: [ntpowershell] How best to retrieve IPv4 (only) addresses from remote computers
[EXTERNAL]
--
Try this:
$NAAdptr = Get-NetIPAddress -AddressFamily IPv4 | Where-Object {$_.IPAddress -like '10.64.*'}
To view this discussion on the web visit https://groups.google.com/d/msgid/ntpowershell/CH3PR07MB9818982492CB98C54D8F65C2D3A59%40CH3PR07MB9818.namprd07.prod.outlook.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ntpowershell/CADy1Ce5Kn9am%2B_RjEZPHt7Z%3Df3KLPL0L%2BH-%3DH-FO9rEogbAsgg%40mail.gmail.com.
You can’t, directly. The required namespace was added in the “great expansion” in Server 2012.
Prior to then you used netsh (which still works):
netsh int ipv4 show ipaddresses
netsh int ipv4 show dnsservers
I wrote a CoreConfigurator script for PS v1/v2 and server core (before MSFT released scmd). It does this. But it’s an enterprise class script (that is, it’s full of documentation and logging and etc.) and won’t be trivial to pull the small pieces out you need. But if you want it, I’ll post it.
Thanks.
Regards,
Michael B. Smith
Managing Consultant
Smith Consulting, LLC
From: ntpowe...@googlegroups.com <ntpowe...@googlegroups.com>
On Behalf Of Mike Leone
Sent: Tuesday, February 21, 2023 3:33 PM
To: ntpowe...@googlegroups.com
Subject: Re: [ntpowershell] How best to retrieve IPv4 (only) addresses from remote computers
I'll tell you the part that's aggravating me now .. looks like I can't use the below commands with some of my hosts, and those arwe still running Win 2008 R2 (don't ask, I've complained for years, and you see where that's gotten me ...)
To view this discussion on the web visit https://groups.google.com/d/msgid/ntpowershell/CAHBr%2B%2Bgf_9CroL4c-QpZOKrC0H6gss0_YpjMe_ofmYzStouS6Q%40mail.gmail.com.
Parsing/using netsh?
To view this discussion on the web visit https://groups.google.com/d/msgid/ntpowershell/CADy1Ce7AGUEjbdbjcA54hK%2Bi%3DvSRyneAkoLxQhm91j9kJcrQNw%40mail.gmail.com.
You can’t, directly. The required namespace was added in the “great expansion” in Server 2012.
Prior to then you used netsh (which still works):
netsh int ipv4 show ipaddresses
netsh int ipv4 show dnsservers
I wrote a CoreConfigurator script for PS v1/v2 and server core (before MSFT released scmd). It does this. But it’s an enterprise class script (that is, it’s full of documentation and logging and etc.) and won’t be trivial to pull the small pieces out you need. But if you want it, I’ll post it.
To view this discussion on the web visit https://groups.google.com/d/msgid/ntpowershell/e87381140eeb48cc9bfda690dae06bcc%40smithcons.com.
Here ya go…
###
### Network-Settings.ps1
###
$L_Gateway_Title = "Gateway Settings"
$L_Gateway_Text = "Do you wish to enter a Gateway Address"
$L_DNS_Primary_Title = "DNS Settings"
$L_DNS_Primary_Text = "Do you wish to make this the Primary DNS Server"
$L_DNS_Title = "DNS Settings"
$L_DNS_Text = "Do you wish to enter a DNS Server"
function Get-NIC( [string]$nic )
{
foreach( $nicName in $Script:arrNicName )
{
if( $nicName -eq $nic )
{
return $true
}
}
Popup "An invalid network interface name was specified" "Find Network Interface Name" $vbError
return $false
}
function NetworkSettings
{
msg $L_Function
msg "NetworkSettings: enter"
$L_Network_Title = "Network Control Panel"
$L_Network_Text =
"Network Settings $nl" +
"********************************************$nl" +
"1 - Display Network Settings $nl" +
"2 - Configure the Network Interface $nl" +
"3 - Rename Network Interface $nl" +
"4 - Enable | Disable Network Interface $nl" +
$nl +
"DNS Settings $nl" +
"********************************************$nl" +
"5 - Add | Remove DNS Servers $nl" +
"6 - Flush | Register DNS Settings $nl" +
$nl +
"iSCSI Menu $nl" +
"********************************************$nl" +
"7 - iSCSI Initiator Settings $nl" +
$nl +
"X - Exit to upper level menu"
while( 1 )
{
$userInput = InputBox $L_Network_Text $L_Network_Title '1'
switch ( $userInput )
{
'1'
{ DisplayNetwork; }
'2'
{ ConfigureNetwork; }
'3'
{ RenameNIC; }
'4'
{ EnableDisableNIC; }
'5'
{ ConfigureDNS; }
'6'
{ FlushDNS; }
'7'
{ iScsiMenu; }
'x'
{ msg "NetworkSettings: exit"; return; }
''
{ msg "NetworkSettings: exit"; return; }
default
{
Popup $L_Bad_Choice $L_Network_Title $vbError
}
}
}
msg "NetworkSettings: exit"
}
function DisplayNetwork
{
msg $L_Function
msg "DisplayNetwork: enter"
[string] $strNetworkFile = tmpFileName
$adapters = gwmi -Query "Select * from Win32_NetworkAdapterConfiguration"
[string] $str = "Network Card Information$nl"
foreach( $o in $adapters )
{
### retrieve the adapter name
### Hive HKLM
$regName = "System\CurrentControlSet\Control\Network\" +
"{4D36E972-E325-11CE-BFC1-08002BE10318}\" +
$o.SettingID +
"\Connection"
$valueName = "Name"
$name = ''
$result = RegRead $hklm $regName $valueName ([ref] $name)
if( $result -ne 0 )
{
$name = '<unknown>'
}
msg "NIC name =" $name
if( $o.IPEnabled )
{
### retrieve and classify all available IP addresses
$ipv4 = @()
$ipv6 = @()
foreach( $ip in $o.IPAddress )
{
if( $ip.IndexOf( ':' ) -ge 0 )
{
$ipv6 += $ip
}
else
{
$ipv4 += $ip
}
}
$strIPv4 = $ipv4 -join ' '
$strIPv6 = $ipv6 -join ' '
### retrieve and classify all available netmasks
$nmv4 = @()
$nmv6 = @()
foreach( $nm in $o.IPSubNet )
{
if( $nm.IndexOf( '.' ) -ge 0 )
{
$nmv4 += $nm
}
else
{
$nmv6 += $nm
}
}
$strNMv4 = $nmv4 -join ' '
$strNMv6 = $nmv6 -join ' '
$str += "==============================================================$nl"
$str += "Adapter Name : " + $name + $nl
$str += "State : IPEnabled = True" + $nl
$str += "Description : " + $o.Description + $nl
$str += "Index : " + $o.Index + $nl
$str += "DHCP Enabled : " + $o.DHCPEnabled + $nl
$str += "MAC Address : " + $o.MACAddress + $nl
if( $strIPv4 -and ( $strIPv4.Length -gt 0 ) )
{
$str += "IP Addresses (v4) : " + $strIPv4 + $nl
}
if( $strIPv6 -and ( $strIPv6.Length -gt 0 ) )
{
$str += "IP Addresses (v6) : " + $strIPv6 + $nl
}
if( $strNMv4 -and ( $strNMv4.Length -gt 0 ) )
{
$str += "IPv4 netmask : " + $strNMv4 + $nl
}
if( $strNMv6 -and ( $strNMv6.Length -gt 0 ) )
{
$str += "IPv6 netmask : " + $strNMv6 + $nl
}
foreach( $gw in $o.DefaultIPGateway )
{
$str += "Default gateway : " + $gw + $nl
}
foreach( $dns in $o.DNSServerSearchOrder )
{
$str += "DNS servers : " + $dns + $nl
}
$nmv6 = $null
$nmv4 = $null
$ipv6 = $null
$ipv4 = $null
}
else
{
$str += "==============================================================$nl"
$str += "Adapter Name : " + $name + $nl
$str += "State : IPEnabled = False" + $nl
$str += "Description : " + $o.Description + $nl
$str += "Index : " + $o.Index + $nl
$str += "MAC Address : " + $o.MACAddress + $nl
}
$str += $nl
}
$str | Out-File -FilePath $strNetworkFile -Force
Get-Exitcode notepad.exe $strNetworkFile
rm $strNetworkFile -EA 0
msg "DisplayNetwork: exit"
}
function RenameNIC
{
msg $L_Function
msg "RenameNIC: enter"
$L_Rename_Title = "Rename Network Interface"
$oldNIC = InputBox "Enter the old name of the Network Interface" $L_Rename_Title $script:arrNicName[ $script:defNicIndex ]
if( !$oldNIC -or ( $oldNIC.Length -eq 0 ) )
{
msg "RenameNIC: exit, no old network interface name was specified"
return
}
if( -not ( Get-NIC $oldNIC ) )
{
msg "RenameNIC: exit, bad NIC name"
return
}
$newNIC = InputBox "Enter the new name of the Network Interface" $L_Rename_Title "Private Network"
if( !$newNIC -or ( $newNIC.Length -eq 0 ) )
{
msg "RenameNIC: exit, no new network interface name was specified"
return
}
$str = 'interface set interface name="' + $oldNIC + '" newname="' + $newNIC + '"'
msg "RenameNIC = '$str'"
$returnValue = 0
if( $Unsafe )
{
$returnValue = Get-Exitcode netsh.exe $str
msg "RenameNIC = $returnValue"
}
else
{
msg "netsh.exe not executed, use Unsafe to make changes. Command would be:"
msg "Get-ExitCode netsh.exe $str"
}
if( $returnValue -eq 0 )
{
Popup "Success: renamed $oldNIC to $newNIC" $L_Rename_Title $vbInformation
}
else
{
Popup "Error: Could not rename NIC $oldNIC (error = $returnValue)" $L_Rename_TItle $vbError
}
msg "RenameNIC: exit"
return
}
function ConfigureNetwork
{
msg $L_Function
msg "ConfigureNetwork: enter"
$L_Configure_Title = "Configure Network Interface"
$L_Configure_Text =
"You can have IP configuration assigned automatically if your $nl" +
"network interface supports this capability (called DHCP). $nl" +
"Otherwise, you will need to assign the proper IP address and $nl" +
"other settings. $nl" +
$nl +
"1 = Obtain an IP address and other settings automatically using DHCP$nl" +
"2 = Use a specified static IP address $nl" +
$nl +
"X - Exit to upper level menu"
### this is for IPv4 only
#### [Regex] $ipRegex = "^(25[0-5]|2[0-4][0-9]|[01]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"
[string] $ipRegex = "\b(([01]?\d?\d|2[0-4]\d|25[0-5])\.){3}([01]?\d?\d|2[0-4]\d|25[0-5])\b"
$userInput = InputBox $L_Configure_Text $L_Configure_Title '1'
switch ( $userInput )
{
'1'
{
$nic = InputBox "Enter the network interface name" $L_Configure_Title $script:arrNicName[ $script:defNicIndex ]
switch ( $nic )
{
'x'
{
msg "ConfigureNetwork: exit (X, NIC name 1)"
return
}
''
{
msg "ConfigureNetwork: exit (Cancel, NIC name 1)"
return
}
}
if( -not ( Get-NIC $nic ) )
{
return
}
$prefix = ' interface ipv4 set '
$suffix = ' name="' + $nic + '" source=dhcp'
$cmd1 = $prefix + 'address' + $suffix
$cmd2 = $prefix + 'dnsserver' + $suffix
$returnValue = 0
if( $Unsafe )
{
$returnValue = Get-ExitCode netsh.exe $cmd1
}
msg "netsh.exe $cmd1"
msg "returnValue = $returnValue"
if( $Unsafe )
{
$returnValue = Get-ExitCode netsh.exe $cmd2
}
msg "netsh.exe $cmd2"
msg "returnValue = $returnValue"
if( $Unsafe )
{
$returnValue = Get-ExitCode ifconfig.exe '/renew'
}
msg "ifconfig.exe /renew"
msg "returnValue = $returnValue"
### FIXME: we should check the returnValue from each program.
### The original source only checks the LAST value (from ifconfig).
msg "ConfigureNetwork: exit (input = 1)"
return
}
'2'
{
### put nothing here, use the fall-thru. all other choices will do a return
break
}
''
{
msg "ConfigureNetwork: exit (Cancel)"
return
}
'x'
{
msg "ConfigureNetwork: exit (X)"
return
}
default
{
msg "ConfigureNetwork: exit ($userInput)"
Popup "Error: Invalid choice ($userInput)" $L_Configure_Title $vbError
return
}
}
### fall-thru -- choice 2
$nic = InputBox "Enter the network interface name" $L_Configure_Title $script:arrNicName[ $script:defNicIndex ]
switch ( $nic )
{
'x'
{
msg "ConfigureNetwork: exit (X, NIC name 2)"
return
}
''
{
msg "ConfigureNetwork: exit (Cancel, NIC name 2)"
return
}
}
if( -not ( Get-NIC $nic ) )
{
return
}
$ipAddress = ''
$netMask = ''
$gateway = ''
$ipAddress = InputBox "Enter the IP address of the network interface" $L_Configure_Title '192.168.1.10'
switch ( $ipAddress )
{
'x'
{
msg "ConfigureNetwork: exit (X, IP address)"
return
}
''
{
msg "ConfigureNetwork: exit (Cancel, IP address)"
return
}
}
[bool] $valid = $ipAddress -match $ipRegex
if( -not $valid )
{
Popup "Value entered for IP Address ($ipAddress) is not valid. Try again." $L_Configure_Title $vbError
return
}
$netMask = InputBox "Enter the netmask for the network interface" $L_Configure_Title '255.255.255.0'
switch ( $netMask )
{
''
{
msg "ConfigureNetwork: exit (Cancel, Netmask)"
return
}
'X'
{
msg "ConfigureNetwork: exit (X, Netmask)"
return
}
}
[bool] $valid = $netMask -match $ipRegex
if( -not $valid )
{
Popup "Value entered for netmask is not valid. Try again." $L_Configure_Title $vbError
return
}
$str = ''
$gateway = ''
$returnValue = MsgBox $L_Gateway_Text $L_Gateway_Title ($vbQuestion + $vbYesNo)
if( $returnValue -eq $vbYes )
{
$gateway = InputBox "Enter the gateway for the network interface" $L_Configure_Title
switch ( $gateway )
{
''
{
msg "ConfigureNetwork: exit (Cancel, gateway)"
return
}
'X'
{
msg "ConfigureNetwork: exit (X, gateway)"
return
}
}
[bool] $valid = $gateway -match $ipRegex
if( -not $valid )
{
Popup "Value entered for gateway is not valid. Try again." $L_Configure_Title $vbError
return
}
$str = ' interface ipv4 set address name="' + $nic + '" source=static address=' +
$ipAddress +
' mask=' +
$netMask +
' gateway=' +
$gateway
}
else
{
$str = ' interface ipv4 set address name="' + $nic + '" source=static address=' +
$ipAddress +
' mask=' +
$netMask
}
msg 'netsh.exe' $str
$returnValue = 0
if( $Unsafe )
{
$returnValue = Get-ExitCode 'netsh.exe' $str
}
msg "command = netsh.exe $str"
msg "returnValue = $returnValue"
if( $returnValue -eq 0 )
{
Popup ( "Success: network interface configured successfully: " + $nic ) $L_Configure_Title $vbInformation
}
else
{
Popup ( "Error: Failed to configure network interface: " + $nic ) $L_Configure_Title $vbError
msg "ConfigureNetwork: exit (configuration failure, returnValue = $returnValue)"
return
}
$dns = ''
$strConfirm = MsgBox $L_DNS_Text $L_Configure_Title ($vbQuestion + $vbYesNo)
if( $strConfirm -eq $vbYes )
{
$dns = InputBox 'Enter the IP address for the DNS server' $L_Configure_Title
if( !$dns -or ( $dns.Length -eq 0 ) -or ( $dns -eq 'x' ) )
{
msg "ConfigureNetwork: exit (DNS)"
return
}
[bool] $valid = $dns -match $ipRegex
if( -not $valid )
{
Popup "Value entered for DNS server is not valid" $L_Configure_Title $vbError
return
}
}
elseif( $strConfirm -eq $vbCancel )
{
msg "ConfigureNetwork: exit (Cancel, DNS server)"
return
}
$str = ' interface ipv4 add dnsserver name="' + $nic + '"' + ' address="' + $dns + '" '
$strConfirm = MsgBox $L_DNS_Primary_Text $L_Configure_Title ($vbQuestion + $vbYesNo)
if( $strConfirm -eq $vbYes )
{
$str += ' index=1'
}
elseif( $strConfirm -eq $vbCancel )
{
msg "ConfigureNetwork: exit (Cancel, primary DNS server)"
return
}
msg 'netsh.exe' $str
$returnValue = 0
if( $Unsafe )
{
$returnValue = Get-ExitCode netsh.exe $str
}
msg "returnValue = $returnValue"
if( $returnValue -ne 0 )
{
Popup "Error: Failed to add DNS server (returnValue = $returnValue)" $L_Configure_Title $vbError
}
else
{
Popup "Success: DNS server was added successfully" $L_Configure_Title $vbInformation
}
msg "ConfigureNetwork: exit"
}
function EnableDisableNIC
{
$L_EnableDisable_Title = "Enable/Disable Network Interface"
msg $L_Function
msg "EnableDisableNIC: enter"
$menu =
"1 - Disable network interface $nl" +
"2 - Enable network interface $nl" +
$nl +
"X - Exit to upper level menu $nl"
$userInput = InputBox $menu $L_EnableDisable_Title '1'
switch ( $userInput )
{
'1'
{
break
}
'2'
{
break
}
''
{
msg "EnableDisableNIC: exit (Cancel)"
return
}
'X'
{
msg "EnableDisableNIC: exit (X)"
return
}
default
{
Popup $L_Bad_Choice $L_EnableDisable_Title $vbError
msg "EnableDisableNIC: return"
return
}
}
$value = 'disabled'
if( $userInput -eq '2' )
{
$value = 'enabled'
}
$nic = InputBox "Enter the network interface name to set $value" $L_EnableDisable_Title $script:arrNicName[ $script:defNicIndex ]
switch ( $nic )
{
'x'
{
msg "EnableDisableNIC: exit (X, NIC name 1)"
return
}
''
{
msg "EnableDisableNIC: exit (Cancel, NIC name 1)"
return
}
}
if( -not ( Get-NIC $nic ) )
{
return
}
$str = ' interface set interface "' + $nic + '" ' + $value
msg "command: netsh.exe $str"
$returnValue = 0
if( $Unsafe )
{
$returnValue = Get-ExitCode netsh.exe $str
}
msg "returnValue = $returnValue"
if( $returnValue -eq 0 )
{
Popup "Success: $value network interface" $L_EnableDisable_Title $vbInformation
}
else
{
Popup "Error: Could not set network interface to $value ($returnValue)" $L_EnableDisable_Title $vbError
}
msg "EnableDisableNIC: return"
return
}
function ConfigureDNS
{
msg $L_Function
msg "ConfigureDNS: enter"
$L_ConfigureDNS_Query =
"Add or remove DNS servers to your network interface settings$nl" +
$nl +
"1 - Add DNS servers $nl" +
"2 - Remove DNS servers $nl" +
$nl +
"X - Exit to upper level menu"
$L_ConfigureDNS_Title = "Add | Remove DNS server"
$userInput = InputBox $L_ConfigureDNS_Query $L_ConfigureDNS_Title '1'
switch ( $userInput )
{
'1'
{
break
}
'2'
{
break
}
''
{
msg "ConfigureDNS: exit (cancel)"
return
}
'X'
{
msg "ConfigureDNS: exit (X)"
return
}
default
{
Popup $L_Bad_Choice $L_ConfigureDNS_Title $vbError
msg "ConfigureDNS: return"
return
}
}
$nic = InputBox "Enter the network interface name" $L_ConfigureDNS_Title $script:arrNicName[ $script:defNicIndex ]
switch ( $nic )
{
'x'
{
msg "ConfigureDNS: exit (X, NIC name 1)"
return
}
''
{
msg "ConfigureDNS: exit (Cancel, NIC name 1)"
return
}
}
if( -not ( Get-NIC $nic ) )
{
return
}
[bool] $removeAll = $false
if( $userInput -eq '2') ## delete
{
$L_RemoveAll_DNS =
"Warning: This will remove DNS servers from $nic$nl" +
$nl +
"1 - Remove a single DNS server $nl" +
"2 - Remove ALL DNS servers $nl" +
$nl +
"X - Exit to upper level menu"
$val = InputBox $L_RemoveAll_DNS $L_ConfigureDNS_Title '1'
switch ( $val )
{
'x'
{
msg "ConfigureDNS: exit (X, All DNS)"
return
}
''
{
msg "ConfigureDNS: exit (Cancel, All DNS)"
return
}
'1'
{
break
}
'2'
{
$removeAll = $true
break
}
default
{
Popup $L_Bad_Choice $L_ConfigureDNS_Title $vbError
msg "ConfigureDNS: return"
return
}
}
}
if( $removeAll )
{
$dns = "all"
}
else
{
$dns = InputBox 'Enter the IP address for the DNS server' $L_ConfigureDNS_Title
if( !$dns -or ( $dns.Length -eq 0 ) -or ( $dns -eq 'x' ) )
{
msg "ConfigureDNS: exit (DNS IP address)"
return
}
[bool] $valid = $dns -match $ipRegex
if( -not $valid )
{
Popup "Value entered for DNS server is not valid: $dns" $L_ConfigureDNS_Title $vbError
msg "ConfigureDNS: exit (bad DNS IP address was specified)"
return
}
}
[bool] $primary = $false
if( $userInput -eq '1' ) ### add dns server
{
$strConfirm = MsgBox $L_DNS_Primary_Text $L_ConfigureDNS_Title ( $vbQuestion + $vbYesNo )
if( $strConfirm -eq $vbYes )
{
$primary = $true
}
elseif( $strConfirm -eq $vbCancel )
{
msg "ConfigureNetwork: exit (Cancel, primary DNS server)"
return
}
}
$value = "delete"
if( $userInput -eq '1' )
{
$value = "add"
}
$str = ' interface ipv4 ' + $value + ' dnsserver name="' + $nic + '"' + ' address=' + $dns
if( $primary )
{
$str += " index=1"
}
msg 'netsh.exe' $str
$returnValue = 0
if( $Unsafe )
{
$returnValue = Get-ExitCode netsh.exe $str
}
msg "returnValue = $returnValue"
if( $returnValue -ne 0 )
{
Popup "Error: Failed to $value DNS server (returnValue = $returnValue)" $L_ConfigureDNS_Title $vbError
}
else
{
$value = "deleted"
if( $userInput -eq '1' )
{
$value = "added"
}
Popup "Success: DNS server was $value successfully" $L_ConfigureDNS_Title $vbInformation
}
msg "ConfigureDNS: exit, returnValue = $($returnValue.ToString())"
}
function FlushDNS
{
msg $L_Function
msg "FlushDNS: enter"
$L_FlushDNS_Title = "Flush | Register DNS"
$L_FlushDNS_Query =
"You can flush all current DNS settings from the client-side $nl" +
"cache or you can re-register all DNS settings for all NICs $nl" +
"on this computer. $nl" +
$nl +
"1 - Flush DNS settings $nl" +
"2 - Register DNS settings $nl" +
$nl +
"X - Exit to upper level menu"
$userInput = InputBox $L_FlushDNS_Query $L_FlushDNS_Title '1'
msg "FlushDNS: userInput = $userInput"
switch ( $userInput )
{
''
{
msg "FlushDNS: exit, cancel"
return
}
'x'
{
msg "FlushDNS: exit, X"
return
}
default
{
Popup $L_Bad_Choice $L_FlushDNS_Title $vbError
msg "FlushDNS: return"
return
}
'1'
{
$returnvalue = 0
msg "ipconfig.exe /flushdns"
if( $Unsafe )
{
$returnValue = Get-ExitCode ipconfig.exe "/flushdns"
}
msg "returnValue = $returnValue"
}
'2'
{
$returnvalue = 0
msg "ipconfig.exe /registerdns"
if( $Unsafe )
{
$returnValue = Get-ExitCode ipconfig.exe "/registerdns"
}
msg "returnValue = $returnValue"
}
}
msg "FlushDNS: exit"
To view this discussion on the web visit https://groups.google.com/d/msgid/ntpowershell/CAHBr%2B%2Bhoz46s7jyVzk5jFr3HBWi2za_g7QsGzr_oEJcR-5Taeg%40mail.gmail.com.