Get-DHCPServers.ps1
something exciting
Some information about the exciting thing
Table of contents generated with markdown-toc
Script
function Get-AuthorizedDHCPServers {
# The configNC is replicated to all DCs in a forest, similar
# to the schema, so this function will get all authorized
# DHCP servers in the forest.
$adsi = [ADSI]( "LDAP://RootDSE" )
$configNC = $adsi.configurationNamingContext.Item( 0 )
$names = @()
$cn = [ADSI]("LDAP://CN=NetServices,CN=Services," + $configNC )
foreach ( $object in $cn.children ) {
if ( $null -ne $object.Properties[ 'dhcpIdentification' ] ) {
if ( $object.dhcpIdentification -eq 'DHCP Server Object' ) {
$names += $object.Name
}
}
}
$names
}
$Servers = Get-AuthorizedDHCPServers
#$ComputerName = "PTHADDS03.FMG.local"
#$ServiceName = "DHCPServer"
#$serviceObj = Get-Service -ComputerName $ComputerName | ?{ $_.ServiceName -eq $serviceName } | Select-Object Name, @{Name="Jeremy";Expression={$._Status}}, Status
#$serviceObj
#http://blogs.technet.com/b/heyscriptingguy/archive/2012/11/12/force-a-domain-wide-update-of-group-policy-with-powershell.aspx
$sessions = New-PSSession -ComputerName $Servers
$Sessions
$serviceObj = Invoke-Command -Session $sessions -ScriptBlock {
$ServiceName = "DHCPServer"
Get-Service | Where-Object { $_.ServiceName -eq $serviceName } | Select-Object -Property Name, @{Name = "State"; Expression = { $_.Status } }
}
$serviceObj
Remove-PSSession $sessions
Download
Please feel free to copy parts of the script or if you would like to download the entire script, simple click the download button. You can download the complete repository in a zip file by clicking the Download link in the menu bar on the left hand side of the page.
Report Issues
You can report an issue or contribute to this site on GitHub. Simply click the button below and add any relevant notes. I will attempt to respond to all issues as soon as possible.