none
powershell question - export Ad computer group to csv - get mac address, name RRS feed

  • Question

  • hi folks

    I haven't looked at scripts in years.

    I need to export all computers from certain AD security groups, and my syntax is rubbish for gettting the MACs!

    the basics which worked were -

    Get-ADGroupMember -Identity "blah blah"|select name, objectGUID |export-csv -path C:\temp\blahblah.csv -NoTypeInformation

    I then tried to add in Get-WMIObject win32_networkadapterconfiguration |select description, macaddress

    that didn't work

    and I tried a few others

    basically I don't know what I am doing wrong not joining the different areas.

    If someone can give me a hand I would appreciate it. I need all the MACs and name for SCCM, I plan to import the csv and just getting objectGUID etc is not helpful.

    Tuesday, December 3, 2019 5:08 AM

Answers

  • Try below:

    $Details = foreach ($computer in (Get-ADGroupMember Computers_Test | Where-Object {$_.ObjectClass -eq "Computer"})){
        $NICDetails = Invoke-Command {Get-WmiObject win32_networkadapterconfiguration -Filter 'ipenabled = "true"'} -ComputerName $computer.Name
        if($NICDetails){
            $computer | Select-Object Name, @{n = "MacAddress"; e = {$NICDetails.MacAddress}}
        }
        else{
            $computer | Select-Object Name, @{n = "MacAddress"; e = {"Unable to find the MACAddress"}}
        }   
    }
    
    
    
    $Details
    #$Details | Export-Csv <SomePath> -NoClobber -NoTypeInformation 

    Mac address is not stored in AD and hence you need to remote to the computer and fetch the same. Also please make sure that the PSRemoting is enabled so that the Invoke-Command works for the computers.

    Tuesday, December 3, 2019 9:10 AM

All replies

  • Please format your code as code: How to Use the Code Feature in a TechNet Forum Post

    Is there a special reason why you're not using Get-NetAdapter?

    And just for curiousity: why do you need the MAC address for SCCM?


    Live long and prosper!

    (79,108,97,102|%{[char]$_})-join''

    Tuesday, December 3, 2019 7:01 AM
  • Try below:

    $Details = foreach ($computer in (Get-ADGroupMember Computers_Test | Where-Object {$_.ObjectClass -eq "Computer"})){
        $NICDetails = Invoke-Command {Get-WmiObject win32_networkadapterconfiguration -Filter 'ipenabled = "true"'} -ComputerName $computer.Name
        if($NICDetails){
            $computer | Select-Object Name, @{n = "MacAddress"; e = {$NICDetails.MacAddress}}
        }
        else{
            $computer | Select-Object Name, @{n = "MacAddress"; e = {"Unable to find the MACAddress"}}
        }   
    }
    
    
    
    $Details
    #$Details | Export-Csv <SomePath> -NoClobber -NoTypeInformation 

    Mac address is not stored in AD and hence you need to remote to the computer and fetch the same. Also please make sure that the PSRemoting is enabled so that the Invoke-Command works for the computers.

    Tuesday, December 3, 2019 9:10 AM
  • hi BOfH-666,

    I haven't used get-netadapter as clearly I am bad at scripts.

    I want the MAC to import all computer information into SCCM using import computer objects :)

    Tuesday, December 3, 2019 9:10 PM
  • I haven't used get-netadapter as clearly I am bad at scripts.

    ... and you're bad at googling as well??  ;-)

    I want the MAC to import all computer information into SCCM using import computer objects :)

    There are usually better ways to import computer objects into SCCM. Especially when you run SCCM in an Active Directory environment as you do obviously. ;-)

    You may ask this in a SCCM related forum. 


    Live long and prosper!

    (79,108,97,102|%{[char]$_})-join''

    Tuesday, December 3, 2019 10:27 PM