Forum Discussion

Edmund_Fearon's avatar
Edmund_Fearon
Copper Contributor
Mar 20, 2024

Powershell script to pull MAC addresses from Intune

I am after the Powershell Commands to retrieve the ethernet MACs of enrolled devices in Intune.

 

The aim is to create a script that pulls the MAC addresses for all enrolled devices at once.

 

Any help would be appreciated.

3 Replies

  • Edmund_Fearon's avatar
    Edmund_Fearon
    Copper Contributor
    I am now using the following:

    $devices = Get-MgDeviceManagementManagedDevice
    if ($devices) {
    foreach ($device in $devices) {
    $output = "Device: $($device.DeviceName)
    Operating System: $($device.OperatingSystem)
    Ethernet MAC: $($device.EthernetMacAddress)"
    Write-Output $output
    $output | Out-File -FilePath $outputFilePath -Append
    }
    }

    This successfully populates the Device name and Operating system for all enrolled devices, but the MAC remains blank. However, if I define $devices as a single device using the device ID, the MAC address populates.
    • dhako94's avatar
      dhako94
      Copper Contributor

      Edmund_Fearon 


      Hi,

      unfortunately the standard output of Get-MgDeviceManagementManagedDevice does not contain the EthernetMacAddress, only the WiFiMacAddress. so you have to call the device again separately here is a script

       

       

      $allIntuneDevices = Get-MgDeviceManagementManagedDevice -All
      $outputFilePath = "C:\temp\IntuneDevices.txt"
      foreach ($intuneDevice in $allIntuneDevices) {
        $singelDevice = Get-MgDeviceManagementManagedDevice -ManagedDeviceId $intuneDevice.ID | Select DeviceName, EthernetMacAddress, OperatingSystem
        $singelDevice | Export-Csv -Path IntuneDevices.csv -Delimiter ";" -Encoding utf8 -IncludeTypeInformation -Append
      
        #or in your format
        $output = "Device: $($singelDevice.DeviceName)
        Operating System: $($singelDevice.OperatingSystem)
        Ethernet MAC: $($singelDevice.WiFiMacAddress)"
        Write-Output $output
        $output | Out-File -FilePath $outputFilePath -Append
      
      }

       

      • JamesAtBryan's avatar
        JamesAtBryan
        Copper Contributor
        Hi Dominik,
        Thank you for the script it was very helpful in getting the mac addresses from Intune, but I just wanted to let you know there is a typo on line 10 it should be Ethernet MAC: $($singelDevice.EthernetMacAddress)"
        but again thank you very much for the script.

        -James

Resources