locked
Powershell command for getting printer mac addresses. RRS feed

  • Question

  • Is there a Powershell command to getting printer mac addresses? I'm just starting to learn Powershell basics. 
    • Edited by MikeK321 Thursday, July 28, 2016 3:05 PM
    Thursday, July 28, 2016 3:03 PM

Answers

  • If you have the IP address of the printer you can run this powershell script:

    param
    (
     $Computer
    )
    $colItems = get-wmiobject -class "Win32_NetworkAdapterConfiguration" -computername $Computer | Where{$_.IpEnabled -Match "True"}  
    foreach ($objItem in $colItems)
    {
         $objItem | select Description,MACAddress  
    }

    Save it as Get-MACAddress.ps1 and run it like:

    Get-MACAddress ip-of-printer


    Best regards, George


    • Edited by George.B.Summers Thursday, July 28, 2016 3:09 PM
    • Marked as answer by MikeK321 Thursday, July 28, 2016 3:15 PM
    Thursday, July 28, 2016 3:08 PM
  • Glad to help. Please mark as answered for others to benefit.

    Best regards, George

    • Marked as answer by MikeK321 Monday, March 13, 2017 2:04 PM
    Thursday, July 28, 2016 3:11 PM
  • Yes! You must change directory to where your script resides. You can do CD powershell-script-directory

    OR: as the suggestion above. You need to type .\Get-MacAddress if you are already in the script directory

    (Old Linux thing adapted by MS)

    Setting up the environment in PS is a bit of work but once done it's a pleasure to use.


    Best regards, George

    • Marked as answer by MikeK321 Monday, March 13, 2017 2:04 PM
    Thursday, July 28, 2016 3:30 PM

All replies

  • If you have the IP address of the printer you can run this powershell script:

    param
    (
     $Computer
    )
    $colItems = get-wmiobject -class "Win32_NetworkAdapterConfiguration" -computername $Computer | Where{$_.IpEnabled -Match "True"}  
    foreach ($objItem in $colItems)
    {
         $objItem | select Description,MACAddress  
    }

    Save it as Get-MACAddress.ps1 and run it like:

    Get-MACAddress ip-of-printer


    Best regards, George


    • Edited by George.B.Summers Thursday, July 28, 2016 3:09 PM
    • Marked as answer by MikeK321 Thursday, July 28, 2016 3:15 PM
    Thursday, July 28, 2016 3:08 PM
  • Thank you!  I didn't know if I posted this in the right forum. 
    Thursday, July 28, 2016 3:10 PM
  • Glad to help. Please mark as answered for others to benefit.

    Best regards, George

    • Marked as answer by MikeK321 Monday, March 13, 2017 2:04 PM
    Thursday, July 28, 2016 3:11 PM
  • Thank you George.  I have one more question.  After you copy the script to the Powershell ISE and save the script as a .ps1 file.  If I type in the Get-MacAddress "printer ip" I don't see the mac address listed but I get an error.  I am new to Powershell.  Do I have to set a path statement to where the comandlet is saved? 

    Get-MacAddress : The term 'Get-MacAddress' is not recognized as the name of a cmdlet, function, script file, or
    operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try
    again.
    At line:1 char:1
    + Get-MacAddress 10.1.32.27
    + ~~~~~~~~~~~~~~
        + CategoryInfo          : ObjectNotFound: (Get-MacAddress:String) [], CommandNotFoundException
        + FullyQualifiedErrorId : CommandNotFoundException


    Suggestion [3,General]: The command Get-MacAddress was not found, but does exist in the current location. Windows PowerS
    hell does not load commands from the current location by default. If you trust this command, instead type: ".\Get-MacAdd
    ress". See "get-help about_Command_Precedence" for more details.
    PS C:\users\em3823da\Documents\Powershell Scripts>



    • Edited by MikeK321 Thursday, July 28, 2016 3:23 PM
    Thursday, July 28, 2016 3:22 PM
  • Yes! You must change directory to where your script resides. You can do CD powershell-script-directory

    OR: as the suggestion above. You need to type .\Get-MacAddress if you are already in the script directory

    (Old Linux thing adapted by MS)

    Setting up the environment in PS is a bit of work but once done it's a pleasure to use.


    Best regards, George

    • Marked as answer by MikeK321 Monday, March 13, 2017 2:04 PM
    Thursday, July 28, 2016 3:30 PM
  • Ok thanks!

    Thursday, July 28, 2016 3:36 PM
  • A valuable case, thank you for sharing:)


    Please mark the reply as an answer if you find it is helpful.

    If you have feedback for TechNet Support, contact tnmff@microsoft.com

    Sunday, July 31, 2016 9:12 AM