37mm
September 2, 2015, 4:45am
1
How do I just select the first output of the macaddress field.
Get-ADComputer -Filter * -Property * | Select-Object name, dnshostname, operatingsystem, operatingsystemservicepack, ipv4address, lastlogondate, logoncount, @{ label = "PingResults"; Expression = { tnc $_.ipv4address -InformationLevel Quiet }},@{ label = "Mac Address"; Expression = ({(Get-WmiObject win32_networkadapter).macaddress})}
When I try this
@{ label = “Mac Address”; Expression = ({(Get-WmiObject win32_networkadapter).macaddress | select @{n=‘Mac Address’;e={ $_.Name.split(‘,’)[0].trim() }}})
I get @{Mac Address=} in the column…
Thanks again for the help!
37mm
September 2, 2015, 4:53am
3
Get-ADComputer -Filter * -Property * | Select-Object name, dnshostname, operatingsystem, operatingsystemservicepack, ipv4address, lastlogondate, logoncount, @{ label = "PingResults"; Expression = { tnc $_.ipv4address -InformationLevel Quiet }},@{ label = "Mac Address"; Expression = ({(Get-WmiObject win32_networkadapter).macaddress | select @{n='Mac Address';e={ $_.Name.split(',')[1].trim() }}})}
this is the full line of code. I am trying to pull mac address on a domain query inventory report
37mm
September 2, 2015, 5:02am
4
Ok soo currently I am only pulling my local address, smh.
How do I pass the computer name for each computer?
37mm
September 2, 2015, 5:11am
5
@{ label = “Mac Address”; Expression={(Get-WmiObject win32_networkadapter -ComputerName $_.name).macaddress}}
This works, but i Get alot of null values
sred13
September 2, 2015, 5:13am
6
Use my logic in the Calculated property, it filters out nulls for you.
Expression={(Get-WmiObject win32_networkadapter -ComputerName $_.Name) | ? MacAddress -ne $null | select -first 1 -expand MacAddress}}
37mm
September 2, 2015, 5:13am
7
This works thanks brother you got the ball rolling!
@{ label = "Mac Address"; Expression={(Get-WmiObject win32_networkadapter -ComputerName $_.name).macaddress -ne $null
37mm
September 2, 2015, 5:15am
8
Saw your post after I posted, Yes that works great now the question how to know that I am getting the mac of the Ethernet connection
If you filter by the adapter type, you can get the macaddress of all of your ethernet adapters. If you need a specific ethernet adapter, you will need to know the name of it.
@{ label = "Mac Address"; Expression={(Get-WmiObject win32_networkadapter | Where-Object {$_.AdapterType -eq "Ethernet 802.3"}).macaddress -ne $null}}
37mm
September 2, 2015, 5:51am
10
Thanks for the input Curtis. I am running it now. I there a reason you ommited the $_.name variable after defining the wmi object? I figure it was a mistake?
Sorry, I was just testing against my local machine, but yes add -ComputerName $_.name back to run against remote machines.
37mm
September 2, 2015, 6:24am
13
I credited you in the creation of tool.
Thanks a bunch shoot me a email g60wall@gmail.com
Cheers!