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 #
Pingback: Powershell - add a Column ,Field, Property to an object | BritV8
Made a small alteration to get all DHCP Info in the domain
# Find all DHCP Server in Domain
$Servers = netsh dhcp show server
$list=@()
foreach ($server in $servers)
{
if($server.indexof(“[“) -gt 0)
{
$list+=$server.substring($server.indexof(“[“)+1,$server.indexof(“]”)-1-$server.indexof(“[“))
}
}
#
$ListofScopesandTheirOptions = $Null
foreach ($DHCPServer in $List)
{
if (Test-Connection -BufferSize 32 -Count 1 -ComputerName $dhcpserver -Quiet)
{
$ErrorActionPreference = “silentlycontinue”
$Scopes = Get-DhcpServerv4Scope -ComputerName $DHCPServer
#For all scopes in the primary server, get the scope options and add them to $LIstofSCopesandTheirOptions
foreach ($Scope in $Scopes)
{
$LIstofSCopesandTheirOptions += Get-DHCPServerv4OptionValue -ComputerName $DHCPServer -ScopeID $Scope.ScopeId |select @{label=”DHCPServer”; Expression= {$DHCPServer}},@{label=”ScopeID”; Expression= {$Scope.ScopeId}},@{label=”ScopeName”; Expression= {$Scope.Name}},*
}
$ErrorActionPreference = “continue”
}
}
#Now we have them all, output them
$LIstofSCopesandTheirOptions |out-gridview
#