Fixed errors in public IP address command (#226)
When no Internet connection is available the command runs into an error: "The remote name could not be resolved: 'ipinfo.io'" Fixed this with a try and catch block The command also runs into an error when Internet Explorer was never started. "Invoke-WebRequest : The response content cannot be parsed because the Internet Explorer engine is not available, or Internet Explorer's first-launch configuration is not complete. Specify the UseBasicParsing parameter and try again" Fixed this with the -UseBasicParsing parameterpull/232/head
parent
113e35c736
commit
691f7e5bc9
|
@ -2,7 +2,15 @@
|
||||||
# Simen Kjeserud (Original creator), Gachnang
|
# Simen Kjeserud (Original creator), Gachnang
|
||||||
|
|
||||||
#Get info about pc
|
#Get info about pc
|
||||||
$computerPubIP=(Invoke-WebRequest ipinfo.io/ip).Content
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
$computerPubIP=(Invoke-WebRequest ipinfo.io/ip -UseBasicParsing).Content
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
$computerPubIP="Error getting Public IP"
|
||||||
|
}
|
||||||
$computerIP = get-WmiObject Win32_NetworkAdapterConfiguration|Where {$_.Ipaddress.length -gt 1}
|
$computerIP = get-WmiObject Win32_NetworkAdapterConfiguration|Where {$_.Ipaddress.length -gt 1}
|
||||||
$IsDHCPEnabled = $false
|
$IsDHCPEnabled = $false
|
||||||
$Networks = Get-WmiObject Win32_NetworkAdapterConfiguration -Filter "DHCPEnabled=$True" | ? {$_.IPEnabled}
|
$Networks = Get-WmiObject Win32_NetworkAdapterConfiguration -Filter "DHCPEnabled=$True" | ? {$_.IPEnabled}
|
||||||
|
@ -171,9 +179,9 @@ $computerSystem.Name
|
||||||
|
|
||||||
"Network: "
|
"Network: "
|
||||||
"=================================================================="
|
"=================================================================="
|
||||||
"Computers MAC adress: " + $computerMAC
|
"Computers MAC address: " + $computerMAC
|
||||||
"Computers IP adress: " + $computerIP.ipaddress[0]
|
"Computers IP address: " + $computerIP.ipaddress[0]
|
||||||
"Public IP adress: " + $computerPubIP
|
"Public IP address: " + $computerPubIP
|
||||||
"RDP: " + $RDP
|
"RDP: " + $RDP
|
||||||
""
|
""
|
||||||
($Network| out-string)
|
($Network| out-string)
|
||||||
|
|
Loading…
Reference in New Issue