Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Wednesday, December 5, 2012 2:22 PM
Well big time noob over here.
Just learning to script...
Could you guys help me? For my work i need to use powershell to pull up all mac addresses + Computer names from AD and input them in a .txt file
All replies (5)
Wednesday, December 5, 2012 2:48 PM âś…Answered | 2 votes
No Problem,
what you could do is, get the winRM Service installed and configured on all Clients in the domain (prerequirement Windows XP SP3 or above)
And then import the list in Powershell and have an invoke-command running on all the computers in the list.
Then export everything in a .csv file.
Here quick and dirty ;-)
$Computers = Import-Csv c:\TEMP\computers.txt
$result = @()
foreach ($c in $Computers){
$nic = Invoke-Command {Get-WmiObject win32_networkadapterconfiguration -Filter 'ipenabled = "true"'} -ComputerName $c.Name
$x = New-Object system.Object | select ComputerName,IPAddress,MAC
$x.Computername = $c.Name
$x.IPAddress = $Nic.IPAddress
$x.Mac = $Nic.MACAddress
$result += $x
}
$result | Export-Csv c:\TEMP\Computerdata.csv -Delimiter ";" -NoTypeInformation
Requirements:
- WinRM Service on the Clients are installed and configured
- Your user has enough rights
- computers text file looks like this
Name
clienta
clientb
clientc
- Computers are on when you run the script
regards
Dan
Wednesday, December 5, 2012 2:28 PM
MAC addresses are not stored in AD.
You can get the computer names from AD, but you'll need to interrogate the computers for the MAC addresses, and you may need to consider the possibility they could have more than one.
[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
Wednesday, December 5, 2012 2:30 PM
Hi,
Sorry to disapoint, but mac-addresses are not stored in the Active Directory as far as i know.
Easiest way to achive this would be to have a script which runs on logon and pushes all that data in a database e.g. SQL express.
Regards
Dan
Wednesday, December 5, 2012 2:35 PM
Hello,
Thanks for your answers guys. Well is it then possible to use powershell to get the computernames from a .txt file and somehow get the mac addresses for it? I'm experimenting with WoL that's why i need the mac addresses.
(Btw im a student my teacher told me it was possible from the AD.... i feel such a dumbass now..)
Wednesday, December 5, 2012 2:44 PM
You need to lay out your requirements a little better.
Computers frequently have multiple NICs. It's not uncommon for servers to have multiple wired NICs, and laptops generally have both a wired and wireless NIC.
You first need to figure out if you need the MAC addresses from all the NICs, just the ones that are enabled, or just the ones that are enabled, and connected, or iin this case, maybe just the ones that are enabled, connected, and WoL, capable.
You're probably looking at a WMI query for the win32_networkadapter class.
[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "