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:

  1.        uses powershell gather scope on server
  2.        for each scope returns leases address state of either inactive or active reservation, prunes regular dhcp leases
  3.        reorganizes table , discards unneeded columns, sizes data fits
  4.        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

Popular posts from this blog

Group Policy Event ID 1058 Error Code 1326 (The user name or password is incorrect)

Suspicious event log Event ID: 4905

DCOM received error "2147746132" from...