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
}