Problems exporting Get-DhcpServerv4Scope output to csv

I work in a very large domain environment. DHCP scopes are created and modified daily. It is really frustrating having to dig through multiple different servers on multiple domains trying to find which one is passing out what IP Scope. I am working to create a script that can run a daily poll the DHCP servers on each domain and export the info the CSV files. If the DHCP server only has 1 scope, it displays fine, but if the server has more than one, it just shows “System.Object” like this
{“ServerName.com”, “System.Object”,“System.Object”,“System.Object”,“System.Object”,“System.Object”,“System.Object”,“System.Object
}
Here is the code that I am trying to use. Any advice would be amazing.

{
#increase buffer limit to unlimited
$FormatEnumerationLimit=-1
$file = “C:\DHCP\DHCP Scopes.csv”

#Poll AD to get list of DHCP Servers
$Servers = Get-DhcpServerInDC

#create empty array
$report = @()

#Loop
foreach($Server in $Servers){

#Poll DHCP servers to get scopes
$scope = Get-DhcpServerv4Scope -ComputerName $Server.IPAddress

#Select what objects are added to the array
$report += [pscustomobject]@{

    'DHCP Host Server' = $Server.DnsName
    'Scope ID' = $scope.ScopeId
    'Subnet Mask' = $scope.SubnetMask
    'Name' = $scope.Name
    'State' = $scope.state 
    'Starting Range' = $scope.StartRange
    'Ending Range' = $scope.EndRange
    'Lease Duration' = $scope.LeaseDuration

}

}
$report | Export-Csv $file
}

Hi, welcome to the forum :wave:

Firstly, when posting code in the forum, please can you use the preformatted text </> button. It really helps us with readability, and copying and pasting your code (we don’t have to faff about replacing curly quote marks to get things working).

How to format code on PowerShell.org

The server is returning an array of scopes, so in the same way that you loop over your servers, you’ll need to loop over the scopes to return the information.

$allScopes = Get-DhcpServerv4Scope -ComputerName $Server.IPAddress

foreach ($scope in $allScopes) {
    [PSCustomObject] @{
        ScopeName = $scope.Name
        etc.
}

What are you doing with this info. though? I can’t imagine it being very useful, particularly in a large environment.

Have you looked into IPAM tools?

The one supplied with Windows server might be sufficient for your needs, but there are plenty of other free and paid options.