Output all DHCP reservations to file with PowerShell
i used "script" make text file containing dhcp reservations, including mac addresses. this need feel free 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:
- uses powershell gather scope on server
- for each scope returns leases address state of either inactive or active reservation, prunes regular dhcp leases
- reorganizes table , discards unneeded columns, sizes data fits
- outputs data text file on c:\ using computer name part of file name
hi,
i suggest using foreach-object instead of foreach , replacing format-table select-object , piping export-csv instead of redirecting text file:
get-dhcpserverv4scope | foreach { get-dhcpserverv4lease -scopeid $_.scopeid | {$_.addressstate -like '*reservation'} } | select-object scopeid,ipaddress,hostname,clientid,addressstate | export-csv ".\$($env:computername)-reservations.csv" -notypeinformation don't retire technet! - (don't give yet - 12,950+ strong , growing)
Windows Server > Windows PowerShell
Comments
Post a Comment