Script to show my computer name and IP address

If you need to know the name of the computer of a user or the IP address, then this tiny PowerShell script can become handy. For example, that information might be required for remote assistance software.

There are some tools out there that show this info, e.g. BgInfo, but they don’t always work. Moreover, some users insist on seeing an unobstructed photo of their puppy they just got from a shelter. That’s a big one!

1) Create a PowerShell script file with this content:

Add-Type -AssemblyName System.Windows.Forms
$ip=get-WmiObject Win32_NetworkAdapterConfiguration|Where {$_.Ipaddress.length -gt 1} 
$ipaddress = $ip.ipaddress[0]
$pcname = [System.Net.Dns]::GetHostName()
[System.Windows.Forms.MessageBox]::Show("My PC name - $pcname `n`nMy IP address - $ipaddress",'About my PC','OK','Information')

This script is a modified combination of scripts out there that other people made, so by no means I’m trying to take any credits for it.

2) Put this script to a network location that every user has Read access to.

3) Create a Shortcut that runs PowerShell and points to that location:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -windowstyle hidden -ExecutionPolicy Bypass -File "\\networklocation\software$\info.ps1"

4) Optionally change its icon.

5) Distribute that Shortcut to all users’ computers through a policy.


RESULT

When users open that Shortcut, a window will pop up, then they can pass all that info to you as an admin:

This Post Has 15 Comments

  1. Rob

    Just what I needed . Thank you very much.

    1. Pavel Bludov

      Awesome, Rob!

  2. Rob

    Hi Pavel, How can the script show all IP addresses? Say you have a PC with a WiFi connection & an Ethernet connection and then connecting in via VPN?

    1. Pavel Bludov

      Rob,
      Replace this:
      $ipaddress = $ip.ipaddress[0]
      With this:
      $ipaddress = $ip.ipaddress -join “; “
      Not the best looking and you might want to do more filtering and digging but that’s how you show them all.

  3. sapiro

    hey Pavel
    how can i add my company logo to the script ?
    and how to make bold text /

    tnx 🙂

    1. Pavel Bludov

      Hi Sapiro,
      As far as I know there is no way to perform either of the tasks you mentioned.

  4. Mutu

    Hi i just tested this script on my non domain laptop its work normally,but when tested this on domain joined laptop i got error and ip address doesnt display.
    there is showed cannot index into a null array ..

    1. Pavel Bludov

      Hi Mutu,
      The only array within that script is the array of IP addresses. So I would suggest you dig into that by checking the script in PowerShell line by line to see what those lines return.

  5. Mutu

    Cannot index into a null array.
    At C:\Users\…….\Desktop\systeminfo.ps1:3 char:28
    + $ipaddress = $ip.ipaddress[ <<<< 0]
    + CategoryInfo : InvalidOperation: (0:Int32) [], RuntimeException
    + FullyQualifiedErrorId : NullArray

    I not good on scripting…

    1. Pavel Bludov

      I’ve got a domain joined PC and it’s working fine. Like I said for some reason you are getting an empty array of IP addresses, none.
      Give Google a shot and try to find different ways of getting IP addresses through PowerShell.

  6. matt

    change this string
    $ip=get-WmiObject Win32_NetworkAdapterConfiguration|Where {$_.Ipaddress.length -gt 1}
    to this
    $ip=Get-NetIPAddress -AddressFamily IPv4|Where {$_.Ipaddress.length -gt 1}

    works for me

  7. Frank M

    What would I need to add if I wanted to drop a link to a site?

    1. Paul Bludov

      Hi Frank,
      I don’t think it’s possible to do that as those pop-up windows are very basic.

  8. Giancarlo

    Hi,

    How can this start automatically with this script clicking on it? If i try (as .ps1 saved) just open the script don t execute it…

Leave a Reply