Output this powershell script to a pop-up window

Hi,

I am getting to grips with Powershell and have butchered some scripts online to try to get what I want. What am I try to achieve is; a powershell script that, when run, will produce a pop-up box (a regular OK/Cancel one is fine) that shows the hostname, local IP address and public IP address. I am nearly there the script below works, but just shows the output in the shell:

$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 }

Open in new window


I have tried replacing the Write-Host commands with
(new-object -ComObject wscript.shell).Popup($IPAddress,$PublicIPAddress,$Computername,0x1)

Open in new window

but Powershell then returns a blank output. Any suggestions?

Thanks...
AlAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David Johnson, CD, MVPOwnerCommented:
$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>","")
#[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null
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 ) 
{
$output =  "Public IP address is " + $FinalIPAddress+ "     "

$output1 = "ComputerName is " + $ComputerName + "     "

$output2 = "Local IP Address is " +$IPAddress + "     "

[System.Windows.Forms.MessageBox]::Show($output1 + $output2 +"     "+ $output,"IP Address",0) 
return  0 }
Else {Write-Host "Script Check Failed" 
return 1001 }
}
catch
{Write-Host "Script Check Failed" 
return 1001 }

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AlAuthor Commented:
Perfect, thanks so much. It's helped me to learn too as I can now understand how you got it to work and why I couldn't. Cheers.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.