Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Output all DHCP reservations to file with PowerShell

$
0
0

I used this "script" to make a text file containing all DHCP reservations, including MAC addresses.  This does what I need but feel free to comment on improvements

Get-DHCPServerV4Scope | ForEach ($ScopeID) {Get-DHCPServerv4Lease -ScopeID $_.ScopeID}|where {$_.AddressState -like "*Reservation"} | Format-Table -Property ScopeId,IPAddress,HostName,ClientID,AddressState -Autosize > c:\$env:computername-Reservations.txt

In plain english:

  1.       Uses powershell to gather all scope on the server
  2.       For each scope returns all leases with an address state of either inactive or active reservation, this prunes regular DHCP leases
  3.       Reorganizes the table and discards unneeded columns, then sizes so all data fits
  4.       Outputs the data to a text file on C:\ using the computer name as part of the file name


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>