scriptingmisaly

If you need to get all DHCP server leases within your network you could use Windows Server 2012 DHCP cmdlets for the task. You need to install the DHCP RSAT module on the server.

$dhcpservers= Get-DhcpServerInDC

$scope= @()

$reportdata= @()

$ping=new-object System.Net.NetworkInformation.Ping                 

foreach ($dhcpserverin$dhcpservers )

    {

        $reply=$null

        $Reply=$ping.send($dhcpserver.DnsName)        

        If ($reply.status -eq“Success”)

        {

$scopes= Get-DhcpServerv4Scope -ComputerName $dhcpserver.dnsname

        If ($scopes-ne$null)

            {

            foreach ($scopein$scopes)

                {

$Leases= Get-DhcpServerv4Lease -ScopeId $scope.ScopeId -ComputerName $dhcpserver.dnsname

                Foreach ($leasein$Leases) {

write-host$ Lease.IPAddress $Lease.HostName

$reportdata+=New-Object-TypeNamePSObject-Property @{

                    Server =$dhcpserver.dnsname

                    Scope =$Lease.ScopeId

                    IP =$Lease.IPAddress

                    Mac =$Lease.ClientID

View original post 56 more words

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

Category

Uncategorized