$url = "http://checkip.dyndns.com"
$webclient = New-Object System.Net.WebClient
$Ip = $webclient.DownloadString($url)
$Ip2 = $Ip.ToString()
$ip3 = $Ip2.Split(" ")
$ip4 = $ip3[5]
$ip5 = $ip4.replace("</body>","")
$FinalIPAddress = $ip5.replace("</html>","")
function Get-IPAddress
{
param
(
[Parameter(ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)]
[String[]]
$Name
)
process
{ $Name | ForEach-Object { try { [System.Net.DNS]::GetHostByName($_) } catch { } }}
}
$ErrorActionPreference = "Stop"
try
{
[string[]]$ComputerName = $env:computername
$Networks = Get-WmiObject Win32_NetworkAdapterConfiguration -Filter "DHCPEnabled=$True" | ? {$_.IPEnabled}
foreach ($Network in $Networks) {
$i = 0
$IPAddress = $Network.IpAddress[0]
$IsDHCPEnabled = $false
If($network.DHCPEnabled) {
$IsDHCPEnabled = $true
}
Else {$i = 1 }
}
If ( $i -eq 0 )
{
Write-Host "Public IP address is $FinalIPAddress"
Write-Host "ComputerName is $ComputerName"
Write-Host "Local IP Address is $IPAddress"
Exit 0 }
Else {Write-Host "Script Check Failed"
Exit 1001 }
}
catch
{Write-Host "Script Check Failed"
Exit 1001 }
(new-object -ComObject wscript.shell).Popup($IPAddress,$PublicIPAddress,$Computername,0x1)
but Powershell then returns a blank output. Any suggestions?Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.
When asked, what has been your best career decision?
Deciding to stick with EE.
Being involved with EE helped me to grow personally and professionally.
Connect with Certified Experts to gain insight and support on specific technology challenges including:
We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE