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 10 months, 1 week ago.

  • Author
  • #54144
    Profile photo of amit aman
    amit aman

    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.


  • #54147
    Profile photo of Erik Sundin
    Erik Sundin


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


    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

    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

You must be logged in to reply to this topic.