DHCP logs backup
Hi all I have been asked to keep DHCP logs for 30 days. Does anyone have a script I can use to backup the DHCP logs on server 2003 so that they do not get overwritten? Many thanks Sjmry
October 5th, 2009 2:23pm
I figured it out - the script is below in case this helps someone else:
# Delete log files older than 30 days
Set-Location "path to share"
Get-ChildItem -Recurse | Where-Object { ( ($_.LastWriteTime.Date -le (Get-Date).Date.AddDays(-30)) ) } | Remove-Item -force
# Get Yestedays Date In Month, Day, Year format
$yesterday = ( Get-Date ( Get-Date ).AddDays(-1) -uformat %m%d%Y )
# Get the first 3 letters of the day name from yesterday
$logdate=( [string]( ( Get-Date ).AddDays(-1).DayofWeek ) ).SubString(0,3)
# Change path to DHCP log folder, copy yesterdays log file to backup location
Set-Location "C:\WINDOWS\System32\dhcp"
Copy-Item "DhcpSrvLog-$logdate.log" "path to share"
# Rename log file with yesterdays date
Set-Location "path to share"
Rename-Item "DhcpSrvLog-$logdate.log" "$yesterday.log"
Free Windows Admin Tool Kit Click here and download it now
October 5th, 2009 5:47pm


