Powershell Get MAC Address

Below is a powershell function used to get a list of MAC addresses on a computer using WMI:

function Get-MACAddress
{
<#
    .SYNOPSIS 
     Displays the list of MAC addresses on a computer.
    .DESCRIPTION
     This function lists all MAC addresses on local computer or a remote one using WMI.
    .EXAMPLE
     Get-MACAddress
     This command returns a list of all MAC addresses on the local computer.
    .EXAMPLE
     Get-MACAddress -ComputerName client01 -Credential $cred
     This command returns a list of all MAC addresses on computer 'client01' using the $cred credentials.
#>
    Param
    (
        [string]$ComputerName = ".",
        [system.management.automation.psCredential]$Credential
    )

    if($Credential)
    {
        Get-WMIObject -Class win32_networkadapterconfiguration -ComputerName $ComputerName -Credential $Credential | Where-Object {$_.macaddress.length -gt 0} | Select-Object -Property Description, MACAddress | Format-Table
    }
    else
    {
        Get-WMIObject -Class win32_networkadapterconfiguration -ComputerName $ComputerName | Where-Object {$_.macaddress.length -gt 0} | Select-Object -Property Description, MACAddress | Format-Table
    }
}

Popular posts from this blog

Syslog Message Collection for OMS from sources that do not support the agent

Generating Alerts On OMS

How to Configure Message Forwarding on a Mailbox Level