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”
Thanks! this saved me a lot of time!
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.
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
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.
How do you send the information generated for the script to a txt file?