Backup all Active Directory authorised DHCP Servers

You may also like...

15 Responses

  1. Tom Day says:

    Wow Lewis awesome script! I edited slightly to backup to a network share. Curious, looking at the backup file that it creates, I don’t see any reference to existing leases. Does this not do that? I am going to set up a test dhcp server to test the restore but i awesome you just restore this file that is created through the restore wizard?

    many thx for the cool script

  2. Lewis says:

    Hmm, strange, it should back up reservations but no, it doesn’t back up leases. They are after all “dynamic” so it shouldn’t matter. The clients themselves will actually request the same address from the DHCP server if it has a pre-existing lease though so it may not be an issue.

    A quick word of warning though – make sure you edit the DUMP files to direct the restored config to the correct target server! The DUMP files include the name of the DHCP server from which it was backed up so that you can just run it through netsh without modification.

    I’ve actually since updated this script to PowerShell v2 and added notifications and event logging if you’re interested.

  3. Lewis says:

    Tom, see a previous post of mine to see how to use the backup script.

    http://www.lewisroberts.com/2011/07/16/quickly-back-up-your-windows-server-dhcp-configuration/

    NB: Remember to edit the output for the new server before running it through netsh!

  4. Anish says:

    Hi Lewis,

    I am getting the below error when executing the script i.e. error in Line 44. I am not familiar with vb scripting. Can you help me?

    C:\dhcpback.vbs(44, 1) Active Directory: A referral was returned from the server

  5. Lewis says:

    You must make sure you run the script using a user account that has permissions to read the DHCP database (DHCP Admins) and as someone that can query the relevant portions of Active Directory (any domain account should permit this).

    Let me know how you get on.

    -Lewis

  6. Anish says:

    I am executing the script with Domain Admin privileges

  7. Lewis says:

    Could be the ever helpful UAC getting in the way.

    Start a Command Prompt as Administrator (right-click, Run as Admin) and then run the script using: cscript C:\Backupscript.vbs

    -Lewis

  8. Anish says:

    That is the way I am executing the script

  9. Anish says:

    OOPS Apologies Lewis… I forgot to modify the script to include my domain name… Now it is working perfect..Brilliant..Thank you

  10. Lewis says:

    Ah, yeah, that would do it. 🙂

    The PowerShell one automatically gets the domain name and location of the Configuration container so you could use that 🙂

    -Lewis

  11. Christof says:

    The created dumpfile doesn’t include DHCP policies. Do you know a way to complete the complete dhcp database?

  12. Lewis says:

    Hi Christof, the above script is ageing now but it generally covered everything required in 2003 – 2012. It has been some time since I looked at a 2012 DHCP Server so I’m not sure where policies would be kept. With 2012 R2 I believe the NETSH DHCP command was removed from Net Shell since Microsoft want you to use PowerShell.

    If you’re backing up 2012R2, look in to Export-DhcpServer (https://technet.microsoft.com/en-us/library/jj590659.aspx) instead. It may be that policies aren’t backed up as part of either Netsh (2003-2012) or Export-DhcpServer for 2012R2. Sorry!

  13. Hi Lewis, My Name is Ameer.. just wanted to check with you on the possibilities of adding a reporting functionality to this script. it would be great if the script can send an HTML report with list of servers backup successfully and also failed..

    just a thought..

  14. SUSHANT JADHAV says:

    Hello,

    I tried Powershell Script but getting below error,

    Backing up DHCP Server “**********”
    Backup of DHCP Server “*******” FAILED!
    Write-EventLog : Cannot validate argument on parameter ‘Message’. The character length of the 333120 argument is too
    long. Shorten the character length of the argument so it is fewer than or equal to “32766” characters, and then try the
    command again.
    At C:\DHCPBackups\DHCPBackup.ps1:60 char:106
    + Write-EventLog -LogName Application -Source $EventSource -EventId 2002 – …
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidData: (:) [Write-EventLog], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.WriteEventLogCommand

  15. Prashant says:

    Hi Lewis,

    I am using powershell version 5 on Windows 2016 Server and when I run the script, I get the below error:
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    .\Backup-Authorized-DHCP-Servers.ps1
    Can’t find the event source to log events under.
    Please register the event source “DHCPBackupScript” before executing this script.
    eg. New-EventLog -source DHCPBackupScript -logname Application
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    How to resolve this

Discover more from lewisroberts.com

Subscribe now to keep reading and get access to the full archive.

Continue reading