Author Posts

September 2, 2015 at 10:15 am

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!

September 2, 2015 at 10:21 am

Two things:

1. You need to add a -ComputerName parameter to your expression, otherwise you're going to be selecting your own Macaddress every time this runs.

2. I think your calculated property code was a bit too complex, too many select statements. I shortened it to the following.

@{ label = "Mac Address"; Expression={(Get-WmiObject win32_networkadapter) | ? MacAddress -ne $null | select -first 1 -expand MacAddress}}

September 2, 2015 at 10:23 am

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

September 2, 2015 at 10:32 am

Ok soo currently I am only pulling my local address, smh.

How do I pass the computer name for each computer?

September 2, 2015 at 10:41 am

@{ label = "Mac Address"; Expression={(Get-WmiObject win32_networkadapter -ComputerName $_.name).macaddress}}

This works, but i Get alot of null values

September 2, 2015 at 10:43 am

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}}

September 2, 2015 at 10:43 am

This works thanks brother you got the ball rolling!

@{ label = "Mac Address"; Expression={(Get-WmiObject win32_networkadapter -ComputerName $_.name).macaddress -ne $null

September 2, 2015 at 10:45 am

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

September 2, 2015 at 10:59 am

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}}

September 2, 2015 at 11:21 am

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?

September 2, 2015 at 11:35 am

Sorry, I was just testing against my local machine, but yes add -ComputerName $_.name back to run against remote machines.

September 2, 2015 at 11:54 am

I credited you in the creation of tool.
Thanks a bunch shoot me a email g60wall@gmail.com
Cheers!