Getting DHCP Server scope from multiple servers

This topic contains 2 replies, has 3 voices, and was last updated by Profile photo of Rob Simmers Rob Simmers 2 weeks, 1 day ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #54144
    Profile photo of amit aman
    amit aman
    Participant

    Hello Team,

    Hope you all are doing good.. back again 🙂

    This time I am trying to get the DHCP server scope from 2 servers and trying to collect the report into a csv file;
    I am using following script;

    $ab = Get-DhcpServerv4Scope
    $a = $ab[6,8]
    foreach($b in $a)
    {
    Get-DhcpServerv4Scope -ComputerName $b.dnsname | Export-Csv c:\report.csv
    }

    This script is giving me the output from only one server and that too randomly. I cross verified it using
    Get-Help Get-DhcpServerv4Scope -full, found that ComputerName parameter is accepting a single value.
    Kindly help me with the workaround.

    Thanks

    #54147
    Profile photo of Erik Sundin
    Erik Sundin
    Participant

    Hey,

    Your problem is not with Get-DhcpServer4Scope, but with Export-Csv, you need to use the -append parameter. From the Help:

    "-Append

    Indicates that this cmdlet adds the CSV output to the end of the specified file. Without this parameter, Export-CSV replaces the file contents without warning.

    This parameter was introduced in Windows PowerShell 3.0."

    #54155
    Profile photo of Rob Simmers
    Rob Simmers
    Participant

    Collect all of the results and then export to a CSV:

    $ab = Get-DhcpServerv4Scope
    $a = $ab[6,8]
    $results = foreach($b in $a) {
        Get-DhcpServerv4Scope -ComputerName $b.dnsname 
    }
    
    $results | Export-Csv c:\report.csv -NoTypeInformation
    
Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.