Export DHCP scope options to file

howbs2002 111 Reputation points
2021-08-06T19:47:12.363+00:00

Is there a PowerShell command to export specific scope options for all scopes on a single server.

For example, the command below gets all scopes on mydhcpserver and exports their properties to a csv file.

However, I only see scope properties and not scope options, such as "Option 043 / Vendor Specific Info".

Get-DhcpServerv4Scope -ComputerName "mydhcpserver" | Select * | export-csv export.csv -NoTypeInformation

I tried a txt file but that is unusable - netsh dhcp server export c:\DHCP\myscopes.txt

Thanks in advance.

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,462 questions
{count} votes

Accepted answer
  1. Rich Matheisen 45,906 Reputation points
    2021-08-06T21:38:47.117+00:00

    Something like this might be what you're looking for:

    $dhcpserver = 'srv01','srv07'  
    $optionids = 3,6  
    $dhcpserver |  
        ForEach-Object{  
            $servername = $_  
            Get-DHCPServerv4Scope -ComputerName $_ |   
                ForEach-Object{  
                    $scopeid = $_.ScopeId  
                    Get-DHCPServerv4OptionValue -ComputerName $_ -ScopeID $scopeid -OptionId $optionids |  
                        ForEach-Object{  
                            [PSCustomObject]@{  
                                DHCPServer = $servername  
                                ScopeID = $scopeid  
                                OptionId = $_.OptionId  
                                Name =  $_.Name  
                                Value = $_.Value -join ';'  
                            }  
                        }  
                }  
             } | Export-Csv c:\junk\scopids.csv -NoTypeInformation  
    

1 additional answer

Sort by: Most helpful
  1. cthivierge 4,056 Reputation points
    2021-08-06T19:53:05.987+00:00

    You can use the PS command: Get-DhcpServerv4OptionValue -ComputerName MyDC -ScopeId 192.168.1.0

    This should give you the result you are looking for

    hth