{"id":532,"date":"2014-06-30T14:48:34","date_gmt":"2014-06-30T14:48:34","guid":{"rendered":"http:\/\/giraffeit.com\/?p=532"},"modified":"2014-06-30T14:48:34","modified_gmt":"2014-06-30T14:48:34","slug":"psdhcpbackup","status":"publish","type":"post","link":"https:\/\/giraffeit.com\/index.php\/2014\/06\/30\/psdhcpbackup\/","title":{"rendered":"Powershell: backup all DHCP servers"},"content":{"rendered":"<p>This script MUST be run on a 2012 server<\/p>\n<p>#you define some share ( eg \\server1dhcpbackup$ \u00a0, and DNS suffix eg my.domain.com<\/p>\n<p>#remove any variables that might have been stored, otherwise it has a bit of a wobble.<br \/>\nRemove-Variable dhcpServer<br \/>\nRemove-Variable dhcpServers<\/p>\n<p>#we are going to do a check first for all files\/folders that are older than X days ( you specify in the code )<br \/>\n# set folder path<br \/>\n$folderloc = &#8220;\\somesharedhcpbackups$&#8221;<\/p>\n<p># set min age of files<br \/>\n$max_days = &#8220;70&#8221;<\/p>\n<p># get the current date<br \/>\n$curr_date = Get-Date<\/p>\n<p># determine how far back we go based on current date<br \/>\n$del_date = $curr_date.AddDays($max_days)<\/p>\n<p># delete the files<br \/>\nGet-ChildItem $folderloc -Recurse | Where-Object { $_.LastWriteTime -lt $del_date } | Remove-Item -Recurse -Confirm:$False<\/p>\n<p>#this bit finds all the servers ( in the DC !) and only returns the chosen suffx\u00a0ones as there are ones in the US<br \/>\n$dhcpServers= Get-DhcpServerInDC | where-object {$_.dnsname \u2013match \u201cdns suffix\u201d}<\/p>\n<p>#going to prepare a timestamp system now. l33t style.<br \/>\n$CurrentDate = Get-Date<br \/>\n$CurrentDate = $CurrentDate.ToString(&#8216;dd-MM-yyyy_hh-mm-ss&#8217;)<\/p>\n<p>#this bit loops and does the dhcp backup. Backs up the files locally to the path you can see, then copys the file to the $severloc ( which is in<br \/>\n#essence just the dhcpservers dns name )<br \/>\nforeach($dhcpServer in $dhcpServers){<br \/>\n$serverloc = $dhcpServer.DnsName<br \/>\n$from = &#8220;\\$serverlocc$DHCPBackups&#8221;<br \/>\nbackup-dhcpserver -ComputerName $dhcpserver.DnsName -Path &#8220;c:DHCPBackups&#8221;<br \/>\nCopy-Item $from \\somesharedhcpbackups$$CurrentDate$serverloc -Recurse }<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This script MUST be run on a 2012 server #you define some share ( eg \\server1dhcpbackup$ \u00a0, and DNS suffix eg my.domain.com #remove any variables that might have been stored, otherwise it has a bit of a wobble. Remove-Variable dhcpServer Remove-Variable dhcpServers #we are going to do a check first for all files\/folders that are &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/giraffeit.com\/index.php\/2014\/06\/30\/psdhcpbackup\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Powershell: backup all DHCP servers&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[],"class_list":["post-532","post","type-post","status-publish","format-standard","hentry","category-bog"],"_links":{"self":[{"href":"https:\/\/giraffeit.com\/index.php\/wp-json\/wp\/v2\/posts\/532","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/giraffeit.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/giraffeit.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/giraffeit.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/giraffeit.com\/index.php\/wp-json\/wp\/v2\/comments?post=532"}],"version-history":[{"count":0,"href":"https:\/\/giraffeit.com\/index.php\/wp-json\/wp\/v2\/posts\/532\/revisions"}],"wp:attachment":[{"href":"https:\/\/giraffeit.com\/index.php\/wp-json\/wp\/v2\/media?parent=532"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/giraffeit.com\/index.php\/wp-json\/wp\/v2\/categories?post=532"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/giraffeit.com\/index.php\/wp-json\/wp\/v2\/tags?post=532"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}