locked
DNS Suffix Search Order return isn't exporting CSV's properly RRS feed

  • Question

  • Just need a quick query in all domains of all DC's DNS Suffix Search Order. The results show just fine, but I'd like them to be exported to an excel. Unfortunately, it's not dropping but one result into the file. Any tips? Below is the code (without the export-csv)

    $Domain = $ENV:USERDOMAIN
    
    $domainroot = (Get-ADDomain).DistinguishedName 
    $DCOU = "OU=Domain Controllers,$domainroot" 
    $DCNames = Get-ADComputer -LDAPFilter "(samaccountname=*)" -SearchBase $dcou | select -expandproperty name 
    foreach ($DCName in $DCNames){ 
            Get-WmiObject Win32_NetworkAdapterConfiguration -ComputerName $dcname | select DNSHostName, DNSDomainSuffixSearchOrder | Format-table -AutoSize
    
    }
    

    Monday, March 31, 2014 11:56 PM

Answers

  • Hi,

    Try it this way:

    Get-ADComputer -Filter * -SearchBase "OU=Domain Controllers,$($(Get-ADDomain).DistinguishedName)" | ForEach {
     
        Get-WmiObject Win32_NetworkAdapterConfiguration -ComputerName $_.Name -Filter 'IPEnabled=True' | ForEach {
    
            $props = @{
                DNSHostName = $_.DNSHostName
                DNSDomainSuffixSearchOrder = ($_ | Select -ExpandProperty DNSDomainSuffixSearchOrder) -join ','
            }
    
            New-Object PsObject -Property $props
    
        }
                                
    } | Export-Csv .\DCDNSReport.csv -NoTypeInformation


    Don't retire TechNet! - (Don't give up yet - 12,700+ strong and growing)

    • Proposed as answer by jrv Tuesday, April 1, 2014 1:14 AM
    • Marked as answer by TechNetResearcher Tuesday, April 1, 2014 11:12 PM
    Tuesday, April 1, 2014 1:10 AM

All replies

  • Hi,

    Try it this way:

    Get-ADComputer -Filter * -SearchBase "OU=Domain Controllers,$($(Get-ADDomain).DistinguishedName)" | ForEach {
     
        Get-WmiObject Win32_NetworkAdapterConfiguration -ComputerName $_.Name -Filter 'IPEnabled=True' | ForEach {
    
            $props = @{
                DNSHostName = $_.DNSHostName
                DNSDomainSuffixSearchOrder = ($_ | Select -ExpandProperty DNSDomainSuffixSearchOrder) -join ','
            }
    
            New-Object PsObject -Property $props
    
        }
                                
    } | Export-Csv .\DCDNSReport.csv -NoTypeInformation


    Don't retire TechNet! - (Don't give up yet - 12,700+ strong and growing)

    • Proposed as answer by jrv Tuesday, April 1, 2014 1:14 AM
    • Marked as answer by TechNetResearcher Tuesday, April 1, 2014 11:12 PM
    Tuesday, April 1, 2014 1:10 AM
  • Hi Cee ,

    Mike's solution should work like a charm. One tidbit of information though, in case it becomes relevant: There is a simple way to get all DCs independent of OUs (though they should of course be in the DC OU):

    Get-ADComputer -Filter {primaryGroupID -eq 516}

    All computers in an AD have the pGID 515, except for DCs :)

    Cheers,
    Fred


    There's no place like 127.0.0.1

    Tuesday, April 1, 2014 7:24 AM
  • That worked perfectly! Thanks!
    Tuesday, April 1, 2014 11:13 PM
  • Thanks for the tip! I'll keep that in mind!
    Tuesday, April 1, 2014 11:14 PM
  • Tuesday, April 1, 2014 11:23 PM