{"id":65,"date":"2012-09-22T11:02:04","date_gmt":"2012-09-22T10:02:04","guid":{"rendered":"http:\/\/www.mostlyharmless.nl\/?p=65"},"modified":"2012-09-22T11:14:04","modified_gmt":"2012-09-22T10:14:04","slug":"how-to-duplicate-reservations-from-one-windows-server-to-another","status":"publish","type":"post","link":"https:\/\/www.mostlyharmless.nl\/index.php\/2012\/09\/22\/how-to-duplicate-reservations-from-one-windows-server-to-another\/","title":{"rendered":"How to duplicate reservations from one Windows server to another?"},"content":{"rendered":"<h1>Simple version<\/h1>\n<p>&nbsp;<\/p>\n<p>Load-balancing your DHCP has been well documented, but the matter of synchronizing your IP reservations has always the fly in the ointment. But no more.<\/p>\n<p>To export DHCP reservations, from the source server:<\/p>\n<p>netsh dhcp server [ip address] scope [scope address] dump&gt;reserv.txt<\/p>\n<p>Open up \u2018reserv.txt\u2019 in a text editor, do a Find-&gt;Replace for the source server IP, change to the destination server IP. Trim out everything in the file except for the reservations themselves.<\/p>\n<p>On the destination server, make sure your scope is already created, and run the following command:<\/p>\n<p>netsh exec C:\\reserv.txt<\/p>\n<p>Tada. The only problem is that as your add more and more reservations, you\u2019ll need to add them to each server that you are load balancing. It\u2019s easier to do that than to do another export.<\/p>\n<p>found at <a href=\"http:\/\/koolbeans.wordpress.com\/2007\/07\/31\/howto-import-and-export-dhcp-reservations-in-server-2003\/\" target=\"_blank\">Link<\/a><\/p>\n<p><!--more--><\/p>\n<h2>continuation of topic<\/h2>\n<p><span style=\"font-family: Tahoma;\">The problematic scenario is the following:<\/span><\/p>\n<p><span style=\"font-family: Tahoma;\">There are two DHCP servers serving the same set of subnets. For each of the subnets which is being served by both the servers there are two scopes one for each server. The scopes are configured in a way that the active address range in one is in the exclusion range of the other. This way we make sure that a particular IP address is not distributed independently of each other. Now there is a small problem if there are reservations. If the admin has configured the reservations in only one of the scopes then he is on for a surprise. The surprise is that the client for whom you have configured the reservation might get a dynamic IP address from the other DHCP server. This can happen in case the DISCOVER sent by the client reaches the server which does not have reservations first. Thus the essential reason for having a reservation is defeated. <\/span><\/p>\n<p><span style=\"font-family: Tahoma;\">The proper way to handle this scenario is: First configure the scope such that the active address range for both the DHCP servers in question is mutually exclusive. Then write a netsh script for the reservations. This script file (let\u2019s call it reservations.txt) would contain for each reservation an entry like: <\/span><\/p>\n<p><span style=\"color: #0000ff; font-family: Courier New;\">dhcp server 10.0.0.1 scope 10.0.0.0 add \u00a0 reservedip 11.0.0.1 &lt;MAC ADDRESS&gt;<\/span><\/p>\n<p><span style=\"font-family: Tahoma;\">Now run this script in the first server 10.0.0.1 by typing:<\/span><\/p>\n<p><span style=\"font-family: Tahoma;\"><span style=\"color: #0000ff;\"><span style=\"font-family: Courier New;\">Netsh exec reservations.txt<\/span> <\/span><\/span><\/p>\n<p><span style=\"font-family: Tahoma;\">After this has been done, you might want to use a word processor to replace the IP address of the server 10.0.0.1 to the IP address of the second DHCP server (say 10.0.0.2). <\/span><\/p>\n<p><span style=\"font-family: Tahoma;\">Once this replacement has been done, you can run the script in the second server. Actually the scripts for both the servers can be run from any place from which there is network connectivity to the DHCP servers. This is because almost most of the operations done through netsh is remotable.<\/span><\/p>\n<p><span style=\"font-family: Tahoma;\">Now for the tough part. If you do have two scopes like what I have mentioned and you did not duplicate the reservations then you have to do the following:<\/span><\/p>\n<p><span style=\"font-family: Tahoma;\">On the DHCP server where you have configured the reservations, you can execute this command for each of the scopes from which you need to export the reservations.<\/span><\/p>\n<p><span style=\"font-family: Tahoma;\"><span style=\"color: #0000ff;\">netsh dhcp server &lt;serverIPAddress&gt; scope &lt;scopeAddress&gt; \u00a0dump&gt;dump.txt<\/span><\/span><\/p>\n<p><span style=\"font-family: Tahoma;\">This will dump all the configuration settings for this scope. At the bottom of the dumped text file, you can see the reservations being dumped. Just copy this reservation settings to a new file say \u201cexportedreserv.txt\u201d.<\/span><\/p>\n<p><span style=\"font-family: Tahoma;\">Append to this file exportedreserv.txt the reservation settings from each of the other scopes.<\/span><\/p>\n<p><span style=\"font-family: Tahoma;\">Now on the target machine, do a <\/span><\/p>\n<p><span style=\"font-family: Tahoma;\"><span style=\"color: #0000ff;\">netsh exec exportedreserv.txt<\/span><\/span><\/p>\n<p><span style=\"font-family: Tahoma;\">You should be done by now. I know it is not completely automatic, but it does save a lot of effort. <\/span><\/p>\n<p>found at <a href=\"http:\/\/blogs.msdn.com\/b\/anto_rocks\/archive\/2005\/02\/28\/381539.aspx\" target=\"_blank\">Link<\/a><\/p>\n<h2>A repyl on this on how to automate it was :<\/h2>\n<p>Thanks! \u00a0This got me started doing more resarch on netsh and I found a way to fully automate this process with a batch file and 2 free utilities (<a title=\"grep for windows\" href=\"http:\/\/www.wingrep.com\/download.htm\" target=\"_blank\">grep.exe<\/a> and <a href=\"http:\/\/gnuwin32.sourceforge.net\/packages\/sed.htm\" target=\"_blank\">sed.exe<\/a>, <a href=\"http:\/\/unxutils.sourceforge.net\/\" target=\"_blank\">alternative <\/a>) \u00a0In my environment I was worried about 2 dhcp servers getting out of sync. \u00a0So this script will purge all reservations from the 2nd server every night, and import the reservations from the 1st server. \u00a0Maybe someone else will find it useful.<\/p>\n<p>REM #&#8211; Dump current DHCP configurations &#8211;#<\/p>\n<p>netsh dhcp server \\\\server1 dump &gt; dhcp_dump.txt<\/p>\n<p>netsh dhcp server \\\\server2 dump &gt; dhcp_purge.txt<\/p>\n<p>REM #&#8211; In the purge file, pull out the reservation details and change &#8220;add&#8221; to &#8220;delete&#8221; &#8211;#<\/p>\n<p>grep reservedip dhcp_purge.txt | sed.exe &#8220;s\/Add\/delete\/&#8221; &gt; dhcp_purge-reservations.txt<\/p>\n<p>REM #&#8211; Purge reservations on the second dhcp server &#8211;#<\/p>\n<p>netsh exec dhcp_purge-reservations.txt<\/p>\n<p>REM #&#8211; In the dump file pull out the reservation details and change server IPs. &#8211;#<\/p>\n<p>grep reservedip dhcp_dump.txt | sed.exe &#8220;s\/&lt;server1 IP&gt;\/&lt;server2 IP&gt;\/&#8221; &gt; dhcp_new-reservations.txt<\/p>\n<p>REM #&#8211; Import the new reservations into the second dhcp server &#8211;#<\/p>\n<p>netsh exec dhcp_new-reservations.txt<\/p>\n<p><!--more--><\/p>\n<h2>Microsoft VBS script<\/h2>\n<h2>Reservation Manager &#8211; A tool to manage reservations<\/h2>\n<p><strong><span style=\"font-size: medium;\">Reservation Manager:<\/span><\/strong><br \/>\nReservations\u00a0are a critical feature in the DHCP server. Reservations\u2019 are generally used for centralized static IP address assignment for critical machines. This way the IP address of the critical machines which serves critical functions in the network will not have dynamically assigned IP address which can change over time. The reservation manager is a tool which will help solve typical reservation-related problems which the network admins might face. More often than not this tool tries to automate problems to recurring customer problems. It tries to solve the following reservation-related problems:<br \/>\n<strong>1) Migrating reservations from one DHCP Server to another on specific subnets.<\/strong><br \/>\nAs a general best-practice, reservations must be duplicated across all DHCP servers serving the same subnet. This particular functionality addresses this best-practice. Without this the admin has to manually dump reservations from one server to another. This command takes 3+ arguments. The first argument tells the destination DHCP server IP address to which the reservations must be copied to. The second argument identifies the IP Address of the source DHCP server. The last argument is either \u2018all\u2019 or identifies the first scope address on which this operation has to be performed. The third argument can be followed by n number of arguments which identify the different subnet\u2019s to which this operation has to be performed.<br \/>\nExample:<br \/>\ncscript rmanager.vbs Rmanager \u2013migrate 10.0.0.1 11.0.0.1 all<br \/>\nThis command will copy all reservations in all scopes from the server 10.0.0.1 to the server 11.0.0.1.<br \/>\ncscript rmanager.vbs Rmanager \u2013migrate 10.0.0.1 11.0.0.1 12.0.0.0 10.0.0.0 11.0.0.0<br \/>\nThis command will copy reservations from the scopes 12.0.0.0 10.0.0.0 and 11.0.0.0 from the server 10.0.0.1 to 11.0.0.1.<br \/>\nFor this command to work properly the specified scope\/scopes should be present in both the servers. An error message will be printed for those scopes for which this condition is not met. Also for those reservations which cannot be added successfully for whatever reason, an error is printed. Also for every successfully migrated reservation, it can be printed.<br \/>\nIn addition to this, this command can also take an additional preview switch which will just print the action which will be taken and not actually take the action. This is especially useful when the admin wants to review the action before doing it.<br \/>\nExample:<br \/>\ncscript rmanager.vbs Rmanager \u2013migrate 10.0.0.1 11.0.0.1 all \u2013preview out.txt<br \/>\ncscript rmanager.vbs Rmanager \u2013migrate 10.0.0.1 11.0.0.1 12.0.0.0 10.0.0.0 11.0.0.0 \u2013preview out.txt<\/p>\n<p><strong>2) Synchronizing reservations on 2 DHCP servers on specific subnets.<\/strong><br \/>\nAs already mentioned, it is a general best-practice for reservations must be duplicated across all DHCP servers serving the same subnet. This particular functionality addresses this best-practice in a more subter way. Instead of copying reservations from one server to another, this option lets the admin to synchronize the reservation lists between two servers. The arguments for this switch is exactly similar to that of the migrate switch. This command also has an optional preview switch.<br \/>\nExample:<br \/>\ncscript rmanager.vbs\u00a0Rmanager \u2013sync 10.0.0.1 11.0.0.1 all<br \/>\nThis command will sync all reservations in all scopes from the server 11.0.0.1 to the server 10.0.0.1.<br \/>\ncscript rmanager.vbs Rmanager \u2013sync 10.0.0.1 11.0.0.1 12.0.0.0 10.0.0.0 11.0.0.0<br \/>\nFor this command to work properly the specified scope\/scopes should be present in both the servers. An error message will be printed for those scopes for which this condition is not met. Also for those reservations which cannot be added successfully for whatever reason, an error is printed. Also for every successfully migrated reservation, it can be printed.<br \/>\nIn addition to this, this command can also take an additional preview switch which will just print the action which will be taken and not actually take the action. This is especially useful when the admin wants to review the action before doing it.<br \/>\nExample:<br \/>\ncscript rmanager.vbs Rmanager \u2013sync 10.0.0.1 11.0.0.1 all \u2013preview out.txt<br \/>\ncscript rmanager.vbs Rmanager \u2013sync 10.0.0.1 11.0.0.1 12.0.0.0 10.0.0.0 11.0.0.0 \u2013preview out.txt<\/p>\n<p><strong>3) Dumping leases on specific subnets.<\/strong><br \/>\nThis command dumps the leases for a specific scope and server into a human-editable text file. The file will contains several lines each of which corresponds to a single lease. A lease is represented by IP address and MAC address. The exact utility of this command will be exposed once you see the next section.<br \/>\nExample:<br \/>\ncscript rmanager.vbs Rmanager -dumplease out.txt 120.0.0.1 all<br \/>\nThe above command dumps all leases in all scopes in the server 120.0.0.1 to a text file called &#8220;out.txt&#8221;<br \/>\ncscript rmanager.vbs Rmanager -dumplease out.txt 120.0.0.1 10.0.0.0 11.0.0.0<br \/>\nThe above command dumps all leases in scopes 10.0.0.0 and 11.0.0.0 in the server 120.0.0.1 to a text file called &#8220;out.txt&#8221;<\/p>\n<p><strong>4) MakeReservation switch.<\/strong><br \/>\nThis switch tries to create reservations on a given DHCP server from the information present in a given input file. The input file contains several lines of info. Each line corresponds to a single reservation. Each reservation is represented by IP address and MAC address pair. The format of this input file is exactly the same as the output file of the -dumplease switch.<br \/>\nExample:<br \/>\ncscript rmanager.vbs Rmanager -makereservation 120.0.0.1 out.txt<br \/>\nThis command will create reservations out of information present in the file out.txt in the server 120.0.0.1.<\/p>\n<p>Based on the -dumplease and -makereservation switch, some interesting possibilities arise. What is possible is the following scenario: An admin has an active DHCP server which has a couple of scopes. Initially there are no reservations in any of these scopes. Thus all the subnets corresponding to these scopes have dynamic addresses. In the environment any machine which is plugged into the these subnets will get a dynamic IP address from the DHCP server. Now to restrict the access of the network to those machines that are already connected to the network, the admin can do the following.<br \/>\ncscript rmanager.vbs Rmanager -dumplease out.txt 120.0.0.1 all<br \/>\ncscript rmanager.vbs Rmanager -makereservation 120.0.0.1 out.txt<br \/>\nThese two commands intends to convert every active lease in a given DHCP server identified by an IP address in a given set of scopes identified by a list of scope addresses into reservations. Once this is done, the admin also has to make sure that the whole address space in the given scope in the DHCP server are excluded. This operation is thus particularly relevant to those admins who might want to move from a pure Dynamic IP address assignment to a more controlled purely reservation oriented address assignment. This way the admin can keep track of who is getting IP addresses and can limit the network access to those clients who already have an IP address.<br \/>\nThe first command Rmanager -dumplease &lt;filename&gt; &lt;Scope Identifiers&gt; will dump all the active leases in the specified server and scope to a text file. This text file will have pair of IP address and MAC addresses. The second command Rmanager \u2013makereservation &lt;ServerIdentifier&gt; &lt;filename&gt; will take the file which is generated by the first command and create reservations corresponding to them. The idea behind separating these two actions is to make sure that the admin gets a chance to edit the file generated by the first command before proceeding to the second. Also we want to support scenarios where the admin can just create the file and use it to run the second command directly.<\/p>\n<p><em>In the attachment (See the link at the end of this post), Find the RManager.vbs .You need to extract the contents of the zip file into a separate folder and run it from there. The zip file should contain two files: rmanager.vbs and help.txt.<\/em><\/p>\n<p><em>\u00a0If you are not able to get it, Cut-copy-paste the following into a file named rmanager.vbs. Also copy the contents of the documentation help.txt<\/em><\/p>\n<p>Run it by typing &#8220;cscript rmanager.vbs&#8221;<\/p>\n<p>X&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;Begin Paste&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;X<\/p>\n<p>call start()<br \/>\ndim scopes<br \/>\ndim synccount<br \/>\ndim argerror<br \/>\ndim iparray<br \/>\ndim macarray<br \/>\ndim finaliparray<br \/>\ndim finalmacarray<br \/>\ndim m<br \/>\ndim args<\/p>\n<p>sub start()<\/p>\n<p>args=0<br \/>\nsynccount=0<br \/>\nargerror=0<br \/>\nif(wscript.arguments.count=0) then<br \/>\nwscript.echo &#8220;enter the command&#8221;<br \/>\nexit sub<br \/>\nend if<\/p>\n<p>for i=0 to wscript.arguments.count-1<br \/>\nif(i=0) then<br \/>\nstr=wscript.arguments.item(i)<br \/>\nelse<br \/>\nstr=str&amp;&#8221; &#8220;&amp;wscript.arguments.item(i)<br \/>\nend if<br \/>\nnext<\/p>\n<p>str1=split(str)<\/p>\n<p>&#8216;show error if nothing is entered&#8212;&#8212;&#8212;&#8212;<\/p>\n<p>if (not isarray(str1)) then<br \/>\nwscript.echo &#8220;Error: unrecongnized or incomplete command line.&#8221;<br \/>\ncall helpfile()<br \/>\nexit sub<br \/>\nend if<br \/>\n&#8216;checking if the command is Rmanager or not<\/p>\n<p>if(strcomp(&#8220;Rmanager&#8221;,str1(0))&lt;&gt;0) then<br \/>\nwscript.echo &#8220;Error: unrecongnized or incomplete command line.&#8221;<br \/>\ncall helpfile()<br \/>\nexit sub<br \/>\nend if<\/p>\n<p>&#8216;checking for different cases after Rmanager<br \/>\nif(ubound(str1)=0) then<br \/>\nwscript.echo &#8220;Error: unrecongnized or incomplete command line.&#8221;<br \/>\ncall helpfile()<br \/>\nexit sub<br \/>\nend if<br \/>\nselect case str1(1)<\/p>\n<p>case &#8220;-migrate&#8221;<\/p>\n<p>call migrate(str1)<\/p>\n<p>case &#8220;-sync&#8221;<\/p>\n<p>call migrate(str1)<br \/>\nif(argerror=1) then<br \/>\nexit sub<br \/>\nend if<br \/>\nsynccount=1<br \/>\na=str1(2)<br \/>\nstr1(2)=str1(3)<br \/>\nstr1(3)=a<br \/>\ncall migrate(str1)<\/p>\n<p>case &#8220;-dumplease&#8221;<\/p>\n<p>call dump(str1)<\/p>\n<p>case &#8220;-makereservation&#8221;<\/p>\n<p>call makereservation(str1)<\/p>\n<p>case &#8220;\/?&#8221;<\/p>\n<p>call helpfile()<\/p>\n<p>case else<br \/>\nwscript.echo &#8220;Error: unrecongnized or incomplete command line.&#8221;<br \/>\ncall helpfile()<\/p>\n<p>end select<\/p>\n<p>&#8216;delete the scopefile that is created during the program<\/p>\n<p>set fso = createobject(&#8220;Scripting.FileSystemObject&#8221;)<br \/>\nif(fso.fileexists(&#8220;scopefile.txt&#8221;))then<br \/>\nfso.deletefile(&#8220;scopefile.txt&#8221;),true<br \/>\nend if<br \/>\nend sub<br \/>\n&#8216; function for dumplease<\/p>\n<p>sub dump(str1)<\/p>\n<p>&#8216;if improper arguments are entered show error<\/p>\n<p>if ubound(str1)&lt;4 then<br \/>\nwscript.echo &#8220;Error: unrecongnized or incomplete command line.&#8221;<br \/>\ncall helpfile()<br \/>\nexit sub<br \/>\nend if<\/p>\n<p>filename = str1(2)<br \/>\nset fso = createobject(&#8220;Scripting.FileSystemObject&#8221;)<br \/>\nSet outfile = fso.CreateTextFile(filename)<br \/>\noutfile.close<\/p>\n<p>p=checkserver(str1(3))<\/p>\n<p>if p=0 then<br \/>\nwscript.echo &#8220;server &#8220;&amp;str1(3)&amp;&#8221; not present or is entered wrongly&#8221;<br \/>\nexit sub<br \/>\nend if<\/p>\n<p>serverarray = makescopearray(scopes)<\/p>\n<p>if not isarray(serverarray) then<br \/>\nwscript.echo &#8220;no scopes in server &#8220;&amp;str1(3)<br \/>\nexit sub<br \/>\nend if<\/p>\n<p>if (strcomp(str1(4),&#8221;all&#8221;)=0) then<\/p>\n<p>if(ubound(str1)=4) then<br \/>\nscope = serverarray<br \/>\nelse<br \/>\nwscript.echo &#8220;improper arguments&#8221;<br \/>\nend if<\/p>\n<p>else<\/p>\n<p>for i = 4 to ubound(str1)<br \/>\nif(isscope(str1(i),serverarray)) then<br \/>\nredim preserve scope(i-4)<br \/>\nscope(i-4)=str1(i)<br \/>\nelse<br \/>\nwscript.echo &#8220;scope &#8220;&amp; str1(i) &amp;&#8221; is not present in server &#8220;&amp;str1(3)<br \/>\nexit sub<br \/>\nend if<br \/>\nnext<br \/>\nend if<br \/>\n&#8216;scope contains all the scopes entered<br \/>\nif not isarray(scope) then<br \/>\nwscript.echo &#8220;no scopes in the server &#8220;&amp;str1(3)<br \/>\nelse<br \/>\nif scope(0)=&#8221;&#8221; then<br \/>\nwscript.echo &#8220;no scopes in the server &#8220;&amp;str1(3)<br \/>\nelse<br \/>\nset wshell = CreateObject(&#8220;WScript.Shell&#8221;)<\/p>\n<p>for i = 0 to ubound(scope)<br \/>\nset obj = wshell.exec(&#8220;netsh dhcp server &#8220;&amp;str1(3)&amp;&#8221; scope &#8220;&amp;scope(i)&amp;&#8221; show clients&#8221;)<br \/>\nclients = obj.stdout.readall()<br \/>\nif(instrrev(clients,&#8221;Command completed successfully.&#8221;)=0) then<br \/>\nexit sub<br \/>\nend if<br \/>\ncall makeclients(clients,str1(2))<br \/>\nnext<br \/>\nend if<br \/>\nend if<br \/>\nif args = 0 then<br \/>\nelse<br \/>\nwscript.echo &#8220;the ipaddress and macaddress pair are in file &#8220;&amp;filename<br \/>\nend if<br \/>\nend sub<\/p>\n<p>&#8217;the following procedure outputs the ip and corresponding mac addresses(active leases) into the file &#8211; &#8216;filename&#8217;&#8230;it takes the output string clients that we get after executing the command shoe clients<\/p>\n<p>sub makeclients(clients,filename)<\/p>\n<p>set fso = createobject(&#8220;Scripting.FileSystemObject&#8221;)<br \/>\nSet scopefile = fso.CreateTextFile(&#8220;scopefile.txt&#8221;)<br \/>\nscopefile.writeline(clients)<br \/>\nscopefile.close<\/p>\n<p>Set scopefile = fso.OpenTextFile(&#8220;scopefile.txt&#8221;)<br \/>\ndo While not scopefile.AtEndOfStream\u00a0\u00a0\u00a0&#8216;reading line by line and checking for the string &#8220;Total No. of Scopes&#8221;<\/p>\n<p>line = scopefile.ReadLine<\/p>\n<p>if(instr(line,&#8221;No of Clients&#8221;)=1) then<br \/>\nstr = split(line)<\/p>\n<p>t=str(4)\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0\u00a0&#8217;taking no. of clients into t<br \/>\nexit do<\/p>\n<p>end if<\/p>\n<p>loop<\/p>\n<p>scopefile.close<\/p>\n<p>t=cint(t)<\/p>\n<p>if t=0 then<br \/>\nwscript.echo &#8220;no clients in the scope &#8220;&amp;str(ubound(str))<\/p>\n<p>exit sub<br \/>\nend if<br \/>\nargs=args+1<br \/>\nSet scopefile = fso.OpenTextFile(&#8220;scopefile.txt&#8221;)<br \/>\nfor i= 1 to 8<br \/>\nscopefile.skipline<br \/>\nnext<\/p>\n<p>set outfile = fso.opentextfile(filename,8)<\/p>\n<p>for i=0 to t-1<br \/>\nline=scopefile.readline<\/p>\n<p>str= split(line)<\/p>\n<p>if (instr(line,&#8221;INACTIVE&#8221;)&lt;&gt;0) then<br \/>\nd=0<br \/>\nfor l=0 to ubound(str)<br \/>\nif(str(l)=&#8221;&#8221;) then<br \/>\nelse<br \/>\nif d=3 then<br \/>\nexit for<br \/>\nelse<br \/>\nd=d+1<br \/>\nend if<br \/>\nend if<br \/>\nnext<\/p>\n<p>outfile.write(str(0))<br \/>\nfor size = 1 to 18-(len(str(0)))<br \/>\noutfile.write(&#8221; &#8220;)<br \/>\nnext<\/p>\n<p>outfile.writeline(trim(replace(str(l),&#8221;-&#8220;,&#8221;&#8221;)))<\/p>\n<p>else<br \/>\nd=0<br \/>\nfor l=0 to ubound(str)<br \/>\nif(str(l)=&#8221;&#8221;) then<br \/>\nelse<br \/>\nif d=4 then<br \/>\nexit for<br \/>\nelse<br \/>\nd=d+1<br \/>\nend if<br \/>\nend if<br \/>\nnext<br \/>\noutfile.write(str(0))<br \/>\nfor size = 1 to 18-(len(str(0)))<br \/>\noutfile.write(&#8221; &#8220;)<br \/>\nnext<\/p>\n<p>outfile.writeline(trim(replace(str(l),&#8221;-&#8220;,&#8221;&#8221;)))<br \/>\nend if<br \/>\nnext<br \/>\noutfile.close<br \/>\nend sub<\/p>\n<p>sub makereservation(str1)<\/p>\n<p>if ubound(str1)&lt;&gt;3 then<br \/>\nwscript.echo &#8220;Error: unrecongnized or incomplete command line.&#8221;<br \/>\ncall helpfile()<br \/>\nexit sub<br \/>\nend if<\/p>\n<p>server = str1(2)<br \/>\nfilename = str1(3)<\/p>\n<p>set fso = createobject(&#8220;Scripting.FileSystemObject&#8221;)<br \/>\nif(not fso.fileexists(filename))then<br \/>\nwscript.echo &#8220;file &#8220;&amp;filename&amp;&#8221; not present&#8221;<br \/>\nexit sub<br \/>\nend if<\/p>\n<p>k = checkserver(server)<br \/>\nif k=0 then<br \/>\nwscript.echo &#8220;server &#8220;&amp;server&amp;&#8221; is not present or may have been entered wrongly&#8221;<br \/>\nexit sub<br \/>\nend if<\/p>\n<p>scopearray=makescopearray(scopes)\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &#8216;scopes is the output string obtained after executing show scope command for given server<\/p>\n<p>set handle = fso.opentextfile(filename)<\/p>\n<p>Dim ipaddress<br \/>\nDim macaddress<br \/>\nt=0<br \/>\ndo while not handle.atendofstream<\/p>\n<p>line=trim(handle.readline)<br \/>\nline=replace(line,&#8221;\u00a0&#8220;,&#8221;&#8221;)<br \/>\nif line=&#8221;&#8221; then<\/p>\n<p>else<br \/>\nstrarray=split(line)<\/p>\n<p>p=0<\/p>\n<p>for k=0 to ubound(strarray)<br \/>\nif strarray(k)=&#8221;&#8221; then<\/p>\n<p>else<\/p>\n<p>if p=0 then<br \/>\nipaddress=trim(strarray(k))<br \/>\nelse if p=1 then<br \/>\nmacaddress = trim(strarray(k))<br \/>\nend if<br \/>\nend if<br \/>\np=p+1<br \/>\n&#8216;wscript.echo Replace(ipaddress, &#8221;\u00a0&#8220;, &#8220;&#8221;)<br \/>\n&#8216;wscript.echo macaddress<br \/>\nend if<br \/>\nnext<\/p>\n<p>if p&lt;&gt;2 then<br \/>\nwscript.echo &#8220;improper format of file&#8221;<br \/>\nexit sub<br \/>\nend if<\/p>\n<p>redim preserve iparray3(t)<br \/>\nredim preserve macarray3(t)<br \/>\niparray3(t)=ipaddress<br \/>\nmacarray3(t)=macaddress<br \/>\nt=t+1<br \/>\nend if<br \/>\nloop<br \/>\nhandle.close<\/p>\n<p>if not isarray(iparray3) then<br \/>\nwscript.echo &#8220;there is nothing in the file&#8221;<br \/>\nexit sub<br \/>\nend if<\/p>\n<p>dim arr<br \/>\nredim arr(t-1)<\/p>\n<p>for i = 0 to ubound(scopearray)<\/p>\n<p>set iprange = fso.createtextfile(&#8220;iprangefile.txt&#8221;)<br \/>\niprange.close<br \/>\narraysize = 0<br \/>\ndim iparray1<br \/>\nredim iparray1(0)<br \/>\nredim macarray1(0)<\/p>\n<p>set wshell = CreateObject(&#8220;WScript.Shell&#8221;)<br \/>\nset obj = wshell.exec(&#8220;netsh dhcp server &#8220;&amp;server&amp;&#8221; scope &#8220;&amp;scopearray(i)&amp;&#8221; show iprange&#8221;)<br \/>\nrange = obj.stdout.readall()<\/p>\n<p>set iprange = fso.opentextfile(&#8220;iprangefile.txt&#8221;,8)<br \/>\niprange.writeline(range)<br \/>\niprange.close<br \/>\nset iprange = fso.opentextfile(&#8220;iprangefile.txt&#8221;)<\/p>\n<p>for p=0 to 5<br \/>\niprange.skipline<br \/>\nnext<br \/>\nline1=iprange.readline<br \/>\nline2=split(line1)<\/p>\n<p>count=0<\/p>\n<p>for j=0 to t-1<\/p>\n<p>k = checkiprange(line2(3),line2(13),iparray3(j))<\/p>\n<p>if k = 1 then<\/p>\n<p>redim preserve iparray1(arraysize)<br \/>\nredim preserve macarray1(arraysize)<br \/>\niparray1(arraysize) = iparray3(j)<br \/>\nmacarray1(arraysize) = macarray3(j)<br \/>\narraysize = arraysize + 1<br \/>\narr(j)=1<br \/>\nelse if k=2 then<br \/>\nwscript.echo &#8220;the ip address &#8220;&amp;iparray3(j)&amp;&#8221; is not valid&#8221;<br \/>\nfso.deletefile(&#8220;iprangefile.txt&#8221;),true<br \/>\nexit sub<br \/>\nend if<br \/>\nend if<br \/>\nnext<\/p>\n<p>iprange.close<br \/>\nif isarray(iparray1) and not iparray1(0)=&#8221;&#8221; then<\/p>\n<p>call addreservation(server,scopearray(i),iparray1,macarray1)<\/p>\n<p>if (finaliparray(0)=&#8221;&#8221;) then<\/p>\n<p>else<br \/>\nfor l=0 to ubound(finaliparray)<br \/>\nset obj = wshell.exec(&#8220;netsh dhcp server &#8220;&amp;server&amp;&#8221; scope &#8221; &amp;scopearray(i)&amp; &#8221; add reservedip &#8220;&amp;finaliparray(l)&amp;&#8221; &#8220;&amp;finalmacarray(l) )<br \/>\noutp = \u00a0obj.stdout.readall()<br \/>\nif(instr(outp,&#8221;Command completed successfully.&#8221;)&lt;&gt;0) then<br \/>\nwscript.echo &#8220;added reservation &#8220;&amp;finaliparray(l)&amp; &#8221; &#8220;&amp;finalmacarray(l)&amp;&#8221; to server &#8220;&amp;server&amp;&#8221; in scope &#8220;&amp;scopearray(i)<br \/>\nelse<\/p>\n<p>wscript.echo &#8220;The specified IP address &#8220;&amp;finaliparray(l)&amp; &#8221; or hardware address &#8220;&amp; finalmacarray(l)&amp; &#8221; is either not proper or is being used by another client.&#8221;<br \/>\nend if<br \/>\nnext<br \/>\nend if<\/p>\n<p>end if<br \/>\nredim iparray1(0)<br \/>\nredim macarray1(0)<\/p>\n<p>next<\/p>\n<p>set handle = fso.opentextfile(filename)<br \/>\nfor i=0 to ubound(arr)<br \/>\nstr=trim(handle.readline)<\/p>\n<p>if(arr(i)=0) then<br \/>\nline=split(str)<\/p>\n<p>wscript.echo &#8220;The ipaddress &#8220;&amp;iparray3(i)&amp;&#8221; is not present in any scope&#8221;<br \/>\nend if<br \/>\nnext<br \/>\nhandle.close<br \/>\nfso.deletefile(&#8220;iprangefile.txt&#8221;),true<br \/>\nend sub<\/p>\n<p>sub addreservation(server,scopestr,iparraysource,macarraysource)<\/p>\n<p>redim finaliparray(0)<br \/>\nredim finalmacarray(0)<br \/>\nset wshell = CreateObject(&#8220;WScript.Shell&#8221;)<br \/>\nset obj = wshell.exec(&#8220;netsh dhcp server &#8220;&amp;server&amp;&#8221; scope &#8221; &amp;scopestr&amp; &#8221; show reservedip&#8221; )<br \/>\noutpdest = obj.stdout.readall()<\/p>\n<p>call makeipandmacarray(outpdest)<br \/>\niparraydest = iparray<br \/>\nmacarraydest = macarray<\/p>\n<p>&#8216; remove common ip and mac pair between the two servers for the given scope<\/p>\n<p>if(not isarray(iparraydest)) then<br \/>\nfinaliparray=iparraysource<br \/>\nfinalmacarray=macarraysource<\/p>\n<p>else<br \/>\nk=0<\/p>\n<p>for i = 0 to ubound(iparraysource)<br \/>\nflag=0<br \/>\nfor j=0 to ubound(iparraydest)<br \/>\nif(iparraysource(i)=iparraydest(j) and macarraysource(i)=macarraydest(j)) then<br \/>\nflag=1<br \/>\nexit for<br \/>\nend if<br \/>\nnext<\/p>\n<p>if flag=1 then<\/p>\n<p>if synccount = 0 and m=0 then<\/p>\n<p>wscript.echo &#8220;reservation &#8220;&amp;iparraysource(i)&amp;&#8221; &#8220;&amp;macarraysource(i)&amp;&#8221; is already present on server &#8220;&amp;server<br \/>\nend if<br \/>\nelse<\/p>\n<p>redim preserve finaliparray(k)<br \/>\nredim preserve finalmacarray(k)<br \/>\nfinaliparray(k)=iparraysource(i)<br \/>\nfinalmacarray(k)=macarraysource(i)<br \/>\nk=k+1<br \/>\nend if<br \/>\nnext<br \/>\nend if<\/p>\n<p>end sub<\/p>\n<p>function checkiprange(ip1,ip2,ip3)<\/p>\n<p>str2=split(ip1,&#8221;.&#8221;)<br \/>\nstr3=split(ip2,&#8221;.&#8221;)<br \/>\nstr4=split(ip3,&#8221;.&#8221;)<br \/>\nif ubound(str4)&lt;&gt;3 then<br \/>\ncheckiprange=2<br \/>\nexit function<br \/>\nend if<\/p>\n<p>dim string<\/p>\n<p>if cint(str2(0))&lt;=cint(str4(0)) and cint(str4(0))&lt;=cint(str3(0)) then<br \/>\nif cint(str2(1))&lt;=cint(str4(1)) and cint(str4(1))&lt;=cint(str3(1)) then<br \/>\nfor i=2 to 3<br \/>\nif(cint(str2(i))&gt;=0 and cint(str2(i))&lt;10) then<br \/>\nstring1=string1&amp;&#8221;00&#8243;&amp;str2(i)<br \/>\nelse if(cint(str2(i))&gt;=10 and cint(str2(i))&lt;100) then<br \/>\nstring1=string1&amp;&#8221;0&#8243;&amp;str2(i)<br \/>\nend if<br \/>\nend if<br \/>\nnext<br \/>\nfor i=2 to 3<br \/>\nif(cint(str3(i))&gt;=0 and cint(str3(i))&lt;10) then<br \/>\nstring2=string2&amp;&#8221;00&#8243;&amp;str3(i)<br \/>\nelse if(cint(str3(i))&gt;=10 and cint(str3(i))&lt;100) then<br \/>\nstring2=string2&amp;&#8221;0&#8243;&amp;str3(i)<br \/>\nend if<br \/>\nend if<br \/>\nnext<br \/>\nfor i=2 to 3<br \/>\nif(cint(str4(i))&gt;=0 and cint(str4(i))&lt;10) then<br \/>\nstring3=string3&amp;&#8221;00&#8243;&amp;str4(i)<br \/>\nelse if(cint(str4(i))&gt;=10 and cint(str4(i))&lt;100) then<br \/>\nstring3=string3&amp;&#8221;0&#8243;&amp;str4(i)<br \/>\nend if<br \/>\nend if<br \/>\nnext<\/p>\n<p>if(cint(string1)&lt;=cint(string3) and cint(string3)&lt;=cint(string2)) then<br \/>\ncheckiprange=1<br \/>\nelse<br \/>\ncheckiprange=0<br \/>\nend if<\/p>\n<p>else<br \/>\ncheckiprange=0<br \/>\nend if<br \/>\nelse<br \/>\ncheckiprange=0<br \/>\nend if<br \/>\nend function<\/p>\n<p>sub helpfile()<\/p>\n<p>set fso = createobject(&#8220;Scripting.FileSystemObject&#8221;)<br \/>\nset help = fso.OpenTextFile(&#8220;help.txt&#8221;)<\/p>\n<p>do while not help.atendofstream<\/p>\n<p>wscript.echo (help.readline)<\/p>\n<p>loop<\/p>\n<p>end sub<\/p>\n<p>&#8216; this function will return 1 if the scope(scopestr) is present in the given server(serverarray&#8230;.this is an array of server scopes)(be it source or destination)&#8230;else 0<\/p>\n<p>function isscope(scopestr,serverarray)<\/p>\n<p>l=0<br \/>\nfor i=0 to ubound(serverarray)<br \/>\nif(strcomp(scopestr,serverarray(i))=0) then<br \/>\nl=1<br \/>\nexit for<br \/>\nend if<br \/>\nnext<\/p>\n<p>isscope=l<\/p>\n<p>end function<\/p>\n<p>&#8217;this function will check if the server entered as argument is present or not(or rather entered correctly or not)<\/p>\n<p>function checkserver(str1)<br \/>\ndim wshell<\/p>\n<p>dim pos1<\/p>\n<p>set wshell = CreateObject(&#8220;WScript.Shell&#8221;)<br \/>\nset obj = wshell.exec(&#8220;netsh dhcp server &#8220;&amp;str1&amp;&#8221; show scope&#8221;)<\/p>\n<p>scopes = obj.stdout.readall()<\/p>\n<p>pos1=instr(scopes,&#8221;Command completed successfully.&#8221;)\u00a0\u00a0\u00a0\u00a0\u00a0 &#8216;if the string is present, the command has executed succesfully<\/p>\n<p>if(pos1&lt;&gt;0) then<br \/>\ncheckserver=1<br \/>\nelse<br \/>\ncheckserver=0<br \/>\nend if<\/p>\n<p>end function<\/p>\n<p>&#8217;this function takes as argument the output string that we get after the command show scope is executed and returns<br \/>\n&#8217;the array of all scopes present in the server<\/p>\n<p>function makescopearray(scopes)<\/p>\n<p>set fso = createobject(&#8220;Scripting.FileSystemObject&#8221;)<br \/>\nSet scopefile = fso.CreateTextFile(&#8220;scopefile.txt&#8221;)<br \/>\nscopefile.writeline(scopes)\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0&#8216;writing output string to a file<br \/>\nscopefile.close<\/p>\n<p>Set scopefile = fso.OpenTextFile(&#8220;scopefile.txt&#8221;)<br \/>\ndo While not scopefile.AtEndOfStream\u00a0\u00a0\u00a0&#8216;reading line by line and checking for the string &#8220;Total No. of Scopes&#8221;<\/p>\n<p>line = scopefile.ReadLine<\/p>\n<p>if(instr(line,&#8221;Total No. of Scopes&#8221;)=2) then<br \/>\nstr = split(line)<br \/>\nt=str(ubound(str)-1)\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0\u00a0&#8217;taking no. of scopes into t<br \/>\nexit do<br \/>\nend if<\/p>\n<p>loop<\/p>\n<p>scopefile.close<\/p>\n<p>t=cint(t)\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&#8216;converting string to integer<\/p>\n<p>if t=0 then\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&#8216;if no scopes are present<\/p>\n<p>makescopearray=&#8221;&#8221;<br \/>\nelse<\/p>\n<p>Set scopefile = fso.OpenTextFile(&#8220;scopefile.txt&#8221;)<br \/>\nfor i=1 to 5<br \/>\nscopefile.skipline\u00a0\u00a0\u00a0\u00a0\u00a0&#8216;skipping first five lines<br \/>\nnext<br \/>\nfor i=0 to t-1<br \/>\nstr3=trim(scopefile.readline)<\/p>\n<p>str3 = split(str3,&#8221; &#8220;)<\/p>\n<p>redim preserve serverscope(i)<br \/>\nserverscope(i)=str3(0)\u00a0\u00a0\u00a0\u00a0\u00a0&#8216;adding scopes to array serverscope<\/p>\n<p>next<br \/>\nmakescopearray = serverscope\u00a0\u00a0\u00a0\u00a0&#8216;returning the array to calling function<br \/>\nscopefile.close<br \/>\nend if<br \/>\nend function<\/p>\n<p>&nbsp;<\/p>\n<p>&#8216;function to take reservations from source server and add to destination server for a given scope<\/p>\n<p>sub reservedip(sourceadd,destadd,scopestr,filename,command)<\/p>\n<p>dim outp<br \/>\nset wshell = CreateObject(&#8220;WScript.Shell&#8221;)<br \/>\nset obj = wshell.exec(&#8220;netsh dhcp server &#8220;&amp;sourceadd&amp;&#8221; scope &#8221; &amp;scopestr&amp; &#8221; show reservedip&#8221; )<br \/>\noutpsource = obj.stdout.readall()<\/p>\n<p>call makeipandmacarray(outpsource)<br \/>\niparraysource = iparray<br \/>\nmacarraysource = macarray<\/p>\n<p>if(not isarray(iparraysource)) then<br \/>\nwscript.echo &#8220;no reservations in the scope &#8220;&amp;scopestr&amp;&#8221; on the server &#8220;&amp;sourceadd<br \/>\nexit sub<br \/>\nend if<br \/>\nif(m=1 or m=2) then<\/p>\n<p>set fso = createobject(&#8220;Scripting.FileSystemObject&#8221;)<br \/>\nSet outfile = fso.openTextFile(filename,8)<\/p>\n<p>for i=0 to ubound(iparraysource)<br \/>\noutfile.writeline(&#8220;netsh dhcp server &#8220;&amp;destadd&amp; &#8221; scope &#8221; &amp;scopestr&amp; &#8221; add reservedip &#8221; &amp;iparraysource(i)&amp; &#8221; &#8221; &amp; macarraysource(i))<br \/>\nnext<br \/>\noutfile.close<br \/>\nexit sub<br \/>\nend if<br \/>\ncall addreservation(destadd,scopestr,iparraysource,macarraysource)<\/p>\n<p>&#8216;now finaliparray and finalmacarray contain only the unique ip and mac addresses<\/p>\n<p>if (not isarray(finaliparray) or finaliparray(0)=&#8221;&#8221;) then<br \/>\nif ((m=1 or m=2)) then<br \/>\nif (strcomp(command,&#8221;-migrate&#8221;)=0 or (strcomp(command,&#8221;-sync&#8221;)=0 and synccount=1)) then<br \/>\nwscript.echo&#8221;output is in file &#8220;&amp;filename<br \/>\nend if<br \/>\nend if<\/p>\n<p>exit sub<br \/>\nend if<\/p>\n<p>t=ubound(finaliparray)<\/p>\n<p>set wshell = CreateObject(&#8220;WScript.Shell&#8221;)<br \/>\nfor i=0 to t<br \/>\nset obj = wshell.exec(&#8220;netsh dhcp server &#8220;&amp;destadd&amp;&#8221; scope &#8221; &amp;scopestr&amp; &#8221; add reservedip &#8221; &amp;finaliparray(i)&amp; &#8221; &#8221; &amp; finalmacarray(i))<br \/>\noutp = \u00a0obj.stdout.readall()<br \/>\nif(instr(outp,&#8221;Command completed successfully.&#8221;)) then<br \/>\nwscript.echo &#8220;added reservation &#8220;&amp;finaliparray(i)&amp; &#8221; &#8220;&amp;finalmacarray(i)&amp;&#8221; to server &#8220;&amp;destadd&amp;&#8221; in scope &#8220;&amp;trim(scopestr)<br \/>\nelse<\/p>\n<p>wscript.echo &#8220;The specified IP address &#8220;&amp;finaliparray(i)&amp; &#8221; or hardware address &#8220;&amp; finalmacarray(i)&amp; &#8221; is being used by another client.&#8221;<br \/>\nend if<\/p>\n<p>next<\/p>\n<p>if ((m=1 or m=2)) then<br \/>\nif (strcomp(command,&#8221;-migrate&#8221;)=0 or (strcomp(command,&#8221;-sync&#8221;)=0 and synccount=1)) then<br \/>\nwscript.echo&#8221;output is in file &#8220;&amp;filename<br \/>\nend if<br \/>\nend if<br \/>\nend sub<\/p>\n<p>sub makeipandmacarray(outp)<br \/>\nredim iparray(0)<br \/>\nredim macarray(0)<\/p>\n<p>set fso = createobject(&#8220;Scripting.FileSystemObject&#8221;)<br \/>\nSet scopefile = fso.CreateTextFile(&#8220;scopefile.txt&#8221;)<br \/>\nscopefile.writeline(outp)<br \/>\nscopefile.close<\/p>\n<p>Set scopefile = fso.openTextFile(&#8220;scopefile.txt&#8221;)<\/p>\n<p>do While not scopefile.AtEndOfStream<br \/>\nline = scopefile.ReadLine<br \/>\nif(instr(line,&#8221;No of ReservedIPs&#8221;)=1) then<br \/>\nstr = split(line)<br \/>\nt=str(4)\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0&#8217;taking no. of reservations into t<br \/>\nexit do<br \/>\nend if<br \/>\nloop<\/p>\n<p>scopefile.close<\/p>\n<p>if t=0 then<br \/>\niparray = &#8220;&#8221;<br \/>\nmacarray = &#8220;&#8221;<br \/>\nexit sub<\/p>\n<p>else<br \/>\nSet scopefile = fso.openTextFile(&#8220;scopefile.txt&#8221;)<\/p>\n<p>for i=1 to 7<br \/>\nscopefile.skipline<br \/>\nnext<\/p>\n<p>for i=1 to t<br \/>\nredim preserve iparray(i-1)<br \/>\nredim preserve macarray(i-1)<br \/>\nstring1=split(trim(scopefile.readline))<\/p>\n<p>iparray(i-1)=string1(0)<br \/>\nmacarray(i-1)=replace(string1(ubound(string1)),&#8221;-&#8220;,&#8221;&#8221;)<br \/>\nnext<br \/>\nend if<br \/>\nscopefile.close<\/p>\n<p>end sub<\/p>\n<p>sub migrate(str1)<\/p>\n<p>if ubound(str1)&lt;4 then\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &#8216; ensures that the command entered has required no. of arguments<br \/>\nwscript.echo &#8220;Error: unrecongnized or incomplete command line.&#8221;<br \/>\ncall helpfile()<br \/>\nargerror=1<br \/>\nexit sub<br \/>\nend if<br \/>\ndim k<\/p>\n<p>k = checkserver(str1(2))\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &#8216;checking if the source server exists or not&#8230;<br \/>\n&#8216;or if they are entered correct or not<br \/>\nif k=0 then<br \/>\nwscript.echo &#8220;server &#8220;&amp;str1(2)&amp; &#8221; not present or is entered wrongly&#8221;<br \/>\nargerror=1<br \/>\nexit sub<br \/>\nend if<\/p>\n<p>scopes1 = scopes<\/p>\n<p>k = checkserver(str1(3))<br \/>\nif k=0 then<br \/>\nwscript.echo &#8220;server &#8220;&amp;str1(3)&amp; &#8221; not present or is entered wrongly&#8221;<br \/>\nargerror=1<br \/>\nexit sub<br \/>\nend if<\/p>\n<p>scopes2 = scopes<\/p>\n<p>&#8216;comes here if both servers are entered correctly<\/p>\n<p>sourcescope = makescopearray(scopes1)\u00a0\u00a0\u00a0\u00a0\u00a0 &#8216;sourcescope here has all scopes from source server<br \/>\nif(isarray(sourcescope)) then\u00a0\u00a0\u00a0\u00a0 &#8216;checking if there are any scopes in source server<br \/>\nelse<br \/>\nwscript.echo &#8220;no scopes present on server &#8220;&amp;str1(2)<br \/>\nargerror=1<br \/>\nexit sub<br \/>\nend if<\/p>\n<p>bound=ubound(str1)<br \/>\nif(strcomp(str1(4),&#8221;all&#8221;)=0) then\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &#8216;checking if the option &#8220;all&#8221; is entered<br \/>\nif(bound&gt;4 and bound&lt;7) then<br \/>\nif(strcomp(str1(5),&#8221;-preview&#8221;)&lt;&gt;0) then<br \/>\nargerror=1<br \/>\nwscript.echo &#8220;Error: unrecongnized or incomplete command line.&#8221;<br \/>\ncall helpfile()<br \/>\nexit sub<br \/>\nelse<br \/>\nif(bound=6) then<br \/>\nfilename = str1(6)<br \/>\nm=2<br \/>\nelse<br \/>\nm=1<br \/>\nfilename = &#8220;output.txt&#8221;<br \/>\nend if<br \/>\nend if<br \/>\nelse<br \/>\nm=0<br \/>\nend if<\/p>\n<p>scope=sourcescope\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &#8216;scope array now contains all the scopes from source server<br \/>\nelse<\/p>\n<p>if(strcomp(str1(bound),&#8221;-preview&#8221;)=0) then<br \/>\nm=1<br \/>\nfilename = &#8220;output.txt&#8221;<br \/>\nelse if(strcomp(str1(bound-1),&#8221;-preview&#8221;)=0) then<br \/>\nm=2<br \/>\nfilename = str1(bound)<br \/>\nelse<br \/>\nm=0<br \/>\nend if<br \/>\nend if<\/p>\n<p>p=0<br \/>\nfor i = 4 to ubound(str1)-m\u00a0\u00a0\u00a0\u00a0\u00a0 &#8217;this is the case when scopes are entered as arguments<br \/>\nif(isscope(str1(i),sourcescope)) then\u00a0\u00a0\u00a0\u00a0 &#8216;checking if the given scope is present in source server<br \/>\nredim preserve scope(p)\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &#8216;if present then add the scope entered to the array &#8216;scope&#8217;<br \/>\nscope(p)=str1(i)<br \/>\np=p+1<br \/>\nelse<br \/>\nif(synccount=0) then\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &#8216;if the scope entered is not present in the source server<br \/>\nwscript.echo &#8220;scope &#8220;&amp;str1(i)&amp; &#8221; is not present in the server &#8220;&amp;str1(2)<br \/>\nend if<br \/>\nend if<br \/>\nnext<br \/>\nend if<\/p>\n<p>erase sourcescope\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &#8216;freeing the space allocated to sourcescope<br \/>\nif(not isarray(scope)) then\u00a0\u00a0\u00a0\u00a0\u00a0 &#8216;checking if the scope array has some scopes or not<br \/>\nargerror=1<br \/>\nexit sub<br \/>\nend if<\/p>\n<p>destscope = makescopearray(scopes2)\u00a0\u00a0\u00a0\u00a0 &#8216;destscope has all scopes from destination server<br \/>\nif(isarray(destscope)) then\u00a0\u00a0\u00a0\u00a0\u00a0 &#8216;checking if there are scopes present on destination server<\/p>\n<p>else<br \/>\nwscript.echo &#8220;no scopes present on server &#8220;&amp;str1(3)<br \/>\nargerror=1<br \/>\nexit sub<br \/>\nend if<\/p>\n<p>if(m=1 or m=2) then<br \/>\nif(synccount=0) then<br \/>\nset fso = createobject(&#8220;Scripting.FileSystemObject&#8221;)<br \/>\nset outfile = fso.createtextfile(filename)<br \/>\noutfile.close<br \/>\nend if<br \/>\nend if<\/p>\n<p>for i=0 to ubound(scope)<\/p>\n<p>if(isscope(scope(i),destscope)) then\u00a0\u00a0\u00a0\u00a0 &#8216;checking if scopes are present on destination server or not<\/p>\n<p>call reservedip(str1(2),str1(3),scope(i),filename,str1(1)) &#8217;this will take reservations in the given scope from source server and output add reservedip(destination) command to a file<\/p>\n<p>else<\/p>\n<p>wscript.echo &#8220;scope &#8220;&amp;scope(i)&amp; &#8221; not present in server &#8220;&amp;str1(3)<br \/>\nend if<br \/>\nnext<br \/>\nif (m=1 or m=2) then<br \/>\nif(strcomp(str1(1),&#8221;-migrate&#8221;)=0 or (strcomp(str1(1),&#8221;-sync&#8221;)=0 and synccount=1)) then<br \/>\nwscript.echo&#8221;output is in file &#8220;&amp;filename<\/p>\n<p>end if<br \/>\nend if<br \/>\nend sub<\/p>\n<p>X&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;End Paste&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;X<\/p>\n<p>And here is a more formal looking help:<br \/>\nUSAGE:<br \/>\nRmanager\u00a0 \/?<br \/>\n-migrate &lt;source server&gt; &lt;destination server&gt; &lt;all|&lt;list of scopes&gt;&gt;<br \/>\n[-preview [filename]]<br \/>\n-sync &lt;server1&gt; &lt;server2&gt; &lt;all | &lt;list of scopes&gt;&gt;<br \/>\n[-preview [filename]]<br \/>\n-dumplease &lt;filename&gt; &lt;server&gt; &lt;all | &lt;listof scopes&gt;&gt;<br \/>\n-makereservation &lt;server&gt; &lt;filename&gt;<\/p>\n<p>Options:<br \/>\n\/?\u00a0\u00a0\u00a0\u00a0 display this help message<br \/>\n-migrate \u00a0\u00a0\u00a0 copies reservations from all or the specified<br \/>\nscopes from source to destination server&#8230;if<br \/>\npreview is specified, it shows the commands that<br \/>\nwill be executed, in the output file<br \/>\n-sync\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 synchronises reservations between two servers for<br \/>\nall or the specified scopes&#8230;.if preview is<br \/>\nspecified, it shows the commands that will be<br \/>\nexecuted, in the output file<br \/>\n-dumplease\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 outputs the ip and macaddresses of all clients in<br \/>\nthe given server for the given scopes<br \/>\n-makereservation\u00a0\u00a0\u00a0 adds reservations for the ip and mac address pairs<br \/>\nfrom the given file into the given server<\/p>\n<p>Examples:<br \/>\n&gt; cscript rmanager.vbs Rmanager -migrate 120.0.0.1 120.0.0.2 all<br \/>\n&#8230;.copies reservations in all scopes from server 120.0.0.1<br \/>\nto server 120.0.0.2<br \/>\n&gt; cscript rmanager.vbs\u00a0Rmanager -sync 120.0.0.1 120.0.0.2 120.0.0.0<br \/>\n&#8230;.synchronises reservations between the two servers<br \/>\n120.0.0.1 and 120.0.0.2 for the scope 120.0.0.0<br \/>\n&gt; cscript rmanager.vbs Rmanager -dumplease out.txt 120.0.0.1 all<br \/>\n&#8230;dumps all clients&#8217; ip and mac addresses into out.txt<br \/>\n&gt; cscript rmanager.vbs Rmanager -makereservation 120.0.0.1 out.txt<br \/>\n&#8230;takes ip and mac address pairs from the file out.txt and<br \/>\nmakes reservation on the server 120.0.0.1<\/p>\n<p>found at <a href=\"http:\/\/blogs.technet.com\/b\/teamdhcp\/archive\/2006\/09\/19\/457383.aspx\" target=\"_blank\">link<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Simple version &nbsp; Load-balancing your DHCP has been well documented, but the matter of synchronizing your IP reservations has always the fly in the ointment. But no more. To export DHCP reservations, from the source server: netsh dhcp server [ip address] scope [scope address] dump&gt;reserv.txt Open up \u2018reserv.txt\u2019 in a text editor, do a Find-&gt;Replace&hellip; <a class=\"more-link\" href=\"https:\/\/www.mostlyharmless.nl\/index.php\/2012\/09\/22\/how-to-duplicate-reservations-from-one-windows-server-to-another\/\">Lees verder <span class=\"screen-reader-text\">How to duplicate reservations from one Windows server to another?<\/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":[14,11,13,12,26],"tags":[36,37,38,40,39],"class_list":["post-65","post","type-post","status-publish","format-standard","hentry","category-ms","category-ms2k3","category-ms2k8","category-ms2k8r2","category-windows-administration","tag-dhcp","tag-export","tag-import","tag-server","tag-windows","entry"],"_links":{"self":[{"href":"https:\/\/www.mostlyharmless.nl\/index.php\/wp-json\/wp\/v2\/posts\/65","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mostlyharmless.nl\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mostlyharmless.nl\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mostlyharmless.nl\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mostlyharmless.nl\/index.php\/wp-json\/wp\/v2\/comments?post=65"}],"version-history":[{"count":7,"href":"https:\/\/www.mostlyharmless.nl\/index.php\/wp-json\/wp\/v2\/posts\/65\/revisions"}],"predecessor-version":[{"id":69,"href":"https:\/\/www.mostlyharmless.nl\/index.php\/wp-json\/wp\/v2\/posts\/65\/revisions\/69"}],"wp:attachment":[{"href":"https:\/\/www.mostlyharmless.nl\/index.php\/wp-json\/wp\/v2\/media?parent=65"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mostlyharmless.nl\/index.php\/wp-json\/wp\/v2\/categories?post=65"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mostlyharmless.nl\/index.php\/wp-json\/wp\/v2\/tags?post=65"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}