Link to home
Start Free TrialLog in
Avatar of Kenneth Platt
Kenneth PlattFlag for Guam

asked on

DHCP Back Up & Export reults to a shared folder

I have been using Netsh to create a back up text file and Database file(db) and automatically copy the results to a server share as follows:
netsh dhcp server dump > \\Server-IP-Address\Sharename$\dhcpcfg.txt
netsh dhcp server export \\Server-IP-Address\Sharename$\dhcpdb all
pause
This worked great with Server 2008 R2 but is not working with Server 2012 R2. Can you please advise me as what the problem and solution might be or another possibly power shell command that might do the same things with the same output?
Avatar of Saad Mardini
Saad Mardini
Flag of Germany image

Hi Kenneth ,


Do you get an error message?
When you say it isn't working, can you be more specific? Is the import not working from 2008? Are you using this purely for investigation?

Thanks
Alex
Avatar of oBdA
oBdA

Since you're asking in PowerShell, that would be
Backup-DhcpServer, Restore-DhcpServer, and Export-DhcpServer
Backup-DhcpServer
https://docs.microsoft.com/en-us/powershell/module/dhcpserver/backup-dhcpserver?view=win10-ps
Restore-DhcpServer
https://docs.microsoft.com/en-us/powershell/module/dhcpserver/restore-dhcpserver?view=win10-ps
Export-DhcpServer
https://docs.microsoft.com/en-us/powershell/module/dhcpserver/export-dhcpserver?view=win10-ps

Backup directory and Export path can reside on a share.
## Target folder will be created if it doesn't exist:
Backup-DhcpServer -Path \\Server-IP-Address\Sharename$\DhcpBackup

Export-DhcpServer -File\\Server-IP-Address\Sharename$\DhcpExport.xml

Open in new window

Hallo Kenneth ,

Hier we go ,

use the following commands :

C:\> Export-DhcpServer -ComputerName "dhcpserver.contoso.com" -File "C:\exportdir\dhcpexport.xml"
Avatar of Kenneth Platt

ASKER

I can run the following successfully locally:
PS C:\Users\admin> Export-DhcpServer -ComputerName SrvName.Contoso.com -File C:\DHCP\dhcpexport.xml
PS C:\Users\admin> Export-DhcpServer -ComputerName SrvName.Contoso.com -File C:\DHCP\dhcpexport.txt
 *****************************************************************************************************

When I try to send the results to a share on another server I get the following:

PS C:\Users\admin> Export-DhcpServer -ComputerName SrvName.Contoso.com -File \\10.10.15.100\DHCP-BUP$\dhcpexport.txt
Exception calling "Create" with "2" argument(s): "The user name or password is incorrect.
"
At C:\windows\system32\windowspowershell\v1.0\Modules\DhcpServer\DhcpServerMigration.psm1:366 char:9
+         $script:writer = [Xml.XmlWriter]::Create($file, $xmlSettings)
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : IOException


PS C:\Users\admin> Export-DhcpServer -ComputerName SrvName.Contoso.com -File \\10.10.15.100\DHCP-BUP$\dhcpexport.xml
Exception calling "Create" with "2" argument(s): "The user name or password is incorrect.
"
At C:\windows\system32\windowspowershell\v1.0\Modules\DhcpServer\DhcpServerMigration.psm1:366 char:9
+         $script:writer = [Xml.XmlWriter]::Create($file, $xmlSettings)
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : IOException
Can't reproduce, works just fine with host name only, FQDN, and IP address.
Then it seems like "admin" doesn't have permissions to write to the target share. Are you running this in an elevated console?
What's the target - a Windows system in the same domain as the DHCP server, a NAS, ...?
What happens when you run the following in the same PS console you ran the "Export" cmdlet:
New-Item -Path \\10.10.15.100\DHCP-BUP$\test.foo -ItemType File

Open in new window

I have tried running PS, PS ISE as an administrator and even running as my own accounts which have the all the big gun group  memberships Ent, Domin Admin, etc. Granted, I'm not a PS expert but I can normally figure things out.
I am at a loss. I am using the same user account that has all the big gun group  memberships Ent, Domin Admin and I am using the same user account that has Share and NTFS Full Control to the root share and all subfolders, etc.
Same thing when I ran New-Item -Path \\10.10.15.100\DHCP-BUP$\test.foo -ItemType File Username and password incorrect
I can accomplish my dhcp db and text file back ups locally and copy the results to the network share. I was interested in automating it through netsh or powershell but I am not seeing progress. If you have an answer, great. If not, thank you for your time
Again: what is "10.10.15.100" - a Windows system in the same domain as the DHCP server, a stand-alone Windows server, a Linux server, a NAS, ...?
Have you tried it against a Windows host in the same domain?
Have you tried using a host name instead of the IP?
Have you tried adding 10.10.15.* as "Local Subnet" in the internet properties?
And just for reference: what happens when you start the good ole cmd.exe and enter
>"\\10.10.15.100\DHCP-BUP$\test.foo" echo foo

Open in new window

Yes, sorry, it's a Windows server in the same domain.
From a command prompt ==>  \\10.10.15.100\DHCP-BUP$\test.foo" echo foo
Result = The user name or password is incorrect
Have you tried it against a Windows host in the same domain? Only other Windows servers
Have you tried using a host name instead of the IP?  No I can. Not sure why using an IP wouldn't work as well if not better than a host name
Have you tried adding 10.10.15.* as "Local Subnet" in the internet properties? I'm not clear on what is meant by adding a subnet in internet properties
Thank you
Well, try using the server's hostname instead of the IP then.
Not sure why using an IP wouldn't work as well if not better than a host name
Because names usually are easier to remember than IP addresses.
Because IPv4 is dying (slowly, but still), and IPv6 addresses are even harder to remember, and even less fun to type ...
Because, for example, IE (and Explorer) will by default treat IP addresses as Internet.
Most important: Because certificates and Kerberos don't work with IP addresses.
I'm not clear on what is meant by adding a subnet in internet properties
Control Panel > Internet Options > Tab "Security" > "Local Intranet" > Button "Sites"
Progress, thank you. foo worked with using the name
It's very late here where I currently am

Will try more tomorrow and report back to you
Thank you
I have worked on it and I am getting some successes but need to work on it more. I will report back.
You have been astronomical help and I thank you
ASKER CERTIFIED SOLUTION
Avatar of Kenneth Platt
Kenneth Platt
Flag of Guam image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I have decided being as I do not know enough about Power Shell that I am going to run Netsh locally and then append an xcopy command to my batch file. Unfortunately, time precludes me from going further.
Thanks especially to oBdA