DHCP – Get a List of Scopes and Scope Options from 2012 R2 DHCP Server

This powershell script gets a list of scopes and scope options from the two servers in a split scope environment. This should work from a 2008 R2 DHCP server and higher It is rough and ready, but it works. I use out-gridview , so I can copy and pate into Excel. You will need to modify the $PrimaryDHCPServer and the $SecondaryDHCPServer to your servers.

I add a property to the object, so that you can tell which scope option is from which server.

See http://britv8.com/powershell-add-a-column-field-property-to-an-object/ for details

 

 

#
$ListofScopesandTheirOptions = $Null
$PrimaryDHCPServer = "2012-dhcp1"
$SecondaryDHCPServer = "2012-dhcp2"
 
#Get all the scopes in the Primary Server
$Scopes = Get-DhcpServerv4Scope -ComputerName $PrimaryDHCPServer
 
#For all scopes in the primary server, get the scope options and add them to $LIstofSCopesandTheirOptions 
foreach ($Scope in $Scopes)
{
$LIstofSCopesandTheirOptions += Get-DHCPServerv4OptionValue -ComputerName $PrimaryDHCPServer -ScopeID $Scope.ScopeId |select @{label=”DHCPServer”; Expression= {$PrimaryDHCPServer}},@{label=”ScopeID”; Expression= {$Scope.ScopeId}},@{label=”ScopeName”; Expression= {$Scope.Name}},*
}
 
#Get all the scopes in the Secondary Server
$Scopes = Get-DhcpServerv4Scope -ComputerName $SecondaryDHCPServer
 
#For all scopes in the secondary server, get the scope options and add them to $LIstofSCopesandTheirOptions 
foreach ($Scope in $Scopes)
{
$LIstofSCopesandTheirOptions += Get-DHCPServerv4OptionValue -ComputerName $PrimaryDHCPServer -ScopeID $Scope.ScopeId |select @{label=”DHCPServer”; Expression= {$PrimaryDHCPServer}},@{label=”ScopeID”; Expression= {$Scope.ScopeId}},@{label=”ScopeName”; Expression= {$Scope.Name}},*
}
 
#Now we have them all, output them
$LIstofSCopesandTheirOptions |out-gridview
#

 

One thought on “DHCP – Get a List of Scopes and Scope Options from 2012 R2 DHCP Server

Leave a comment

Your email address will not be published. Required fields are marked *