Solved

Backup DHCP server database using powershell on share location

Posted on 2015-01-14
3
1,079 Views
Last Modified: 2015-01-19
Hello,

is anybody has powershell script for backing up DHCP server on the share location?

i tried netsh command which used for backing up DHCP server but it stored all database files on the same server.

thanks in advance
takecofffe
0
Comment
Question by:Haresh Nikumbh
3 Comments
 
LVL 14

Accepted Solution

by:
JAN PAKULA earned 250 total points
Comment Utility
Use code from

http://poshcode.org/4017


Discovers DHCP online servers and if SystemRoot\Windows\System32\DHCP\Backup exists, copies the folder on each server to a network share (\\network\share\hostname).

Accepts two parameters:
SearchBase – Location of domain’s configuration container.
BackupDestRoot – Base folder where a folder for each host will be created to contain the copied DHCP database backups

Usage:
.\Backup-DhcpServers.ps1 -SearchBase “cn=configuration,dc=domain,dc=com” -BackupDestRoot “\\network\share\”

Two functions:
Get-OnlineDhcpServers
Backup-DhcpServers

No comment-based help.
No logging.
No error handling.

Known Issues:
BackupDestRoot parameter MUST end with a backslash (\). The script will eventually add a DHCP server’s hostname to this path to create that server’s backup destination.


###############################################
Import-Module ActiveDirectory
 
param (
    [Parameter(Position=1)]
    $searchBase = "cn=configuration,dc=domain,dc=com",
    [Parameter(Position=2)]
    $backupDestRoot = "\\network\share\"
)
 
function Get-OnlineDhcpServers {
    param (
        [Parameter(Mandatory=$true,Position=1)]
        $dhcpSearchBase
        )
    $arrDhcpServers = Get-ADObject -SearchBase $dhcpSearchBase -Filter "objectclass -eq 'dhcpclass' -AND name -ne 'dhcproot'"
    ForEach ($dhcpServer in $arrDhcpServers) {
        if (!(Test-Connection -ComputerName $dhcpServer.name -Count 2 -Quiet -ErrorAction SilentlyContinue)) {
            $arrDhcpServers = @($arrDhcpServers | Where-Object {$_.name -ne $dhcpServer.name})
        }
    }
    return $arrDhcpServers
}
 
function Backup-DhcpServers {
    param (
        [Parameter(Mandatory=$true,Position=1)]
        $arrDhcpBackupSrcNames,
        [Parameter(Mandatory=$true,Position=2)]
        $dhcpBackupDestRoot
    )
    ForEach ($dhcpBackupSrcName in $arrDhcpBackupSrcNames) {
        $dhcpBackupSrc = "\\" + $dhcpBackupSrcName + "\c$\Windows\System32\Dhcp\Backup"
        $dhcpBackupDest = $dhcpBackupDestRoot + $dhcpBackupSrcName
        if (Test-Path -Path $dhcpBackupSrc) {
            Remove-Item -Path $dhcpBackupDest -Recurse -Force -Verbose
            New-Item -Path $dhcpBackupDest -ItemType Directory
            Copy-Item -Path $dhcpBackupSrc -Destination $dhcpBackupDest -Recurse -Verbose
        }
    }
}
 
$onlineDhcpServers = Get-OnlineDhcpServers -dhcpSearchBase $searchBase
$onlineDhcpServerNames = $onlineDhcpServers | ForEach-Object {$_.name.Split(".")[0]}
Backup-DhcpServers -arrDhcpBackupSrcNames $onlineDhcpServerNames -dhcpBackupDestRoot $backupDestRoot

#############################################
0
 
LVL 53

Assisted Solution

by:Will Szymkowski
Will Szymkowski earned 250 total points
Comment Utility
If you do not use server 2012 then you cannot use the new DHCP cmdlets. However the script center has created a nice easy script that will export DHCP config for your servers. Take a look at the below link where you can download this from the Microsoft Script Center.

Export DHCP Settings (Microsoft Script Center)

Will.
0
 
LVL 21

Author Closing Comment

by:Haresh Nikumbh
Comment Utility
Thanks
0

Featured Post

Do email signature updates give you a headache?

Do you feel like you are constantly making changes to email signatures? Are the images not formatting how you want them to? Want high-quality HTML signatures on all devices, including on mobiles and Macs? Then, let Exclaimer solve all your email signature problems today.

Join & Write a Comment

New Windows 7 Installations take days for Windows-Updates to show up and install. This can easily be fixed. I have finally decided to write an article because this seems to get asked several times a day lately. This Article and the Links apply to…
In this article, we will see the basic design consideration while designing a Multi-tenant web application in a simple manner. Though, many frameworks are available in the market to develop a multi - tenant application, but do they provide data, cod…
This tutorial will walk an individual through the steps necessary to enable the VMware\Hyper-V licensed feature of Backup Exec 2012. In addition, how to add a VMware server and configure a backup job. The first step is to acquire the necessary licen…
This tutorial will walk an individual through the steps necessary to install and configure the Windows Server Backup Utility. Directly connect an external storage device such as a USB drive, or CD\DVD burner: If the device is a USB drive, ensure i…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now