PowerShell: Get the hostname, mac, and IP remotely

PowerShell: Get the hostname, mac, and IP remotely

Normally I look around and find scripts to do things I need right away, sadly today, that was not the case! So, I looked at a few websites and was able to come up with this:

$machines = Get-Content feedme.txt
foreach($machinename in $machines)
{
get-wmiobject win32_networkadapterconfiguration -computer $machinename -filter "IPEnabled='True'" | Select DNSHostname,MACAddress,IPAddress
}

Basically how it works is, you put your script and feedme.txt file in the same folder, the feedme.txt file has all of the machine names, then you run the script and it outputs all the machines with the IP and MAC address next to it. Hope this helps, I am sure there are other scripts written that do the same if not similar things with more detail, but this is what I came up with in about 15 minutes (yes, I am slow at this!).

5 thoughts on “PowerShell: Get the hostname, mac, and IP remotely

  1. This is great. Do you have a way of scanning a network to populate the feedme file because I’m trying to scan across about 1000 servers and as you can appreciate that is just a little bit too much to have to find and type out.

  2. If you want to query AD (if you have AD that is) for all servers, for instance, use this to populate the feedme file

    import-module activedirectory
    Get-ADComputer -Filter {OperatingSystem -Like “Windows Server*”} -Property * | Format-Table Name | Out-file c:”Somefilename”.txt

    1. Steve, this is a great addition! When I wrote this, I had a list of servers already but didn’t think about someone who might be looking to compile a list.

Leave a Reply to Salomon Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.