There was a requirement from one of our client to get the below details from each of the DHCP server:
- Server Name
- Name
- Subnet
- Dns Server
- IP Range
- Total Ips
- Free Ips
- Lease Period
Again, Thx to the creator of DHCP powershell module…
Download the script zip from below link, extract it
https://github.com/VikasSukhija/Downloads/blob/master/DHCP.zip
Run the batch file to get the below report:
################################################################## # Author: Vikas SUkhija (http://techwizard.cloud) # Description: Find DHCP SCope Options Values # for particular scope option # Date: 12/17/2014 # Modified: 12/6/2015 # Update: Included subnet.subnetname,primarydns,secondarydns, # Total Ips, Free Ips, Leaseperiod #################################################################### ############Import Module & define variables################## Import-module .\Microsoft.DHCP.PowerShell.Admin.psm1 $collection =@() $idval = "6" ### DNS Scope Option $date = get-date -format d $date = $date.ToString().Replace(“/”, “-”) $time = get-date -format t $time = $time.ToString().Replace(":", "-") $time = $time.ToString().Replace(" ", "") $output = ".\" + "DHCPScopeOptions_" + $date + "_" + $time + "_.csv" ########################################## $srv = Show-DHCPServers $servers= $srv | select server $servers | foreach{ $server = $_.server Write-host "Processing Server...............$server" -foregroundcolor Green $scope=Get-DHCPScope -server $server #$scope $scp = $scope | where {$_.state -like "Active"} | Select Name,Address,IPRanges,Lease #$scp $scp | foreach{ $addr = $_.Address $opt = Get-DHCPScope -server $server -scope $_.Address $sts = Get-DHCPStatistics -Server $server | Select -expandproperty ScopeStatistics | where{$_.scope -like $addr} | select TotalAddresses,Usedaddresses $optscope = $opt | Select -expandproperty options | where{$_.optionId -like $idval} | select Values $coll = “” | select ServerName,Name,Subnet,DNSserver,IPRange,TotalIPs,FreeIps,LeasePeriod $Tot = $sts.TotalAddresses $used = $sts.UsedAddresses $free = [int]$Tot -[int]$used $coll.ServerName = $server $coll.Name = $_.Name $coll.Subnet = $_.Address $coll.DNSserver = $optscope.values $coll.IPrange = $_.IPRanges $coll.TotalIPs = $sts.TotalAddresses $coll.FreeIps = $free $coll.LeasePeriod = $_.Lease $collection += $coll } } $collection | select ServerName,Name,Subnet,@{Name=”DNSserver”;Expression={$_.DNSserver}},@{Name=”IPRange”;Expression={$_.IPRange}},TotalIPs,FreeIps,Leaseperiod | export-csv $output -notypeinfo #######################################################################
Tech Wizard
How can i execute this script on a standaalone DHCP server?
The server is a windows 2008 R2 box.
How can i run this script on a standalone DHCP server?
I tried multiple modifications, nothing working
What error you are getting as it should work fine ..We even executed it from remote machine..