0

I work in a very large network. Dozens of DCHP servers with several departments making changes daily. I am trying to write a script that I can run daily that will poll all of the servers and get the scope info and export to a single csv file. My script works fine when the server only has a single scope, but I get this error when the server contains multiple scopes. "server.domain.com","System.Object[]","System.Object[]","System.Object[]","System.Object[]","System.Object[]","System.Object[]","System.Object[]"`


Here is what I am using now.
`
#increase buffer limit to unlimited
$FormatEnumerationLimit=-1
$file = "C:\DHCP\DHCP Scopes.csv"


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


#Loop
foreach($Server in $Servers){


#create empty array
$report = @()

#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 -NoTypeInformation -Append
}
`
I need the CSV to show what DCHP server is advertising what scope. I have it creating the empty array at the beginning of each loop and exporting at the end of each loop but if the server contains multiple scopes, It just shows the object and not the details. Any assistance would be amazing.
  • `Export-Csv` and `ConvertTo-Csv` do not meaningfully support objects with properties that contain _collections_, such as arrays. If you want to represent all collection elements in a single CSV column value, you'll have to create a string representation of the collection yourself. See the linked duplicate for details. – mklement0 Nov 12 '22 at 17:07

0 Answers0