Solved

Backup DHCP server database using powershell on share location

Posted on 2015-01-14
3
1,497 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 14

Accepted Solution

by:
JAN PAKULA earned 250 total points
ID: 40549548
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
ID: 40549568
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 22

Author Closing Comment

by:Haresh Nikumbh
ID: 40558073
Thanks
0

Featured Post

Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here's a look at newsworthy articles and community happenings during the last month.
Resolving an irritating Remote Desktop connection that stops your saved credentials from being used.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…
Suggested Courses

630 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