#!/usr/bin/perl -w ##################################### # # Script Name: iisexport.pl # Written by: Billy Strader # E-Mail Address: losts@mindspring.com # Purpose: To export IIS setting and import to another box such as a D +R box. # Notes: This script ONLY works on Windows 2003 Server with IIS 6.0. # The account that runs this script will need Administrator ac +cess to both servers. # ##################################### use strict; use File::Copy; use Win32::Service; # Set the main server you wish to export data for my $server = "myserver"; # Set the server you wish to import the data to my $drserver = "mydrserver"; # Set the domain my $domain = "mydomain.com"; # Set any variables such as IP's you wish to have changed from 1 syste +m to the other my %ips = ( "192.168.0.1" => "192.168.0.100", "192.168.0.2" => "192.168.0.200"); # First lets remove the old files if they exist if (-f "\\\\$server.$domain\\c\$\\$server.xml") { unlink("\\\\$server.$domain\\c\$\\$server.xml"); } if (-f "\\\\$server.$domain\\c\$\\new$server.xml") { unlink("\\\\$drserver.$domain\\c\$\\new$server.xml"); } if (-f "\\\\$drserver.$domain\\c\$\\$server.xml") { unlink("\\\\$drserver.$domain\\c\$\\$server.xml"); } if (-f "\\\\$drserver.$domain\\c\$\\new$server.xml") { unlink("\\\\$drserver.$domain\\c\$\\new$server.xml"); } # Now lets runs the iiscnfg command to export the entire IIS setup system("iiscnfg /s $server.$domain /export /f c:\\$server.xml /sp /lm +/children"); # Open the file and dump it to an array so we can go through it open(FILE, "c:\\$server.xml"); my @file = <FILE>; close(FILE); # Create new file and for each entry in the replace catagory lets repl +ace those selected items. open(NEWFILE, ">c:\\new$server.xml"); foreach my $line (@file) { chomp $line; foreach my $ip (sort(keys %ips)){ my $newip = $ips{$ip}; $line =~ s/$ip/$newip/ig; } print NEWFILE "$line\n"; } close(NEWFILE); # Lets now copy the new file to the DR server my $srcfile = "\\\\$server.$domain\\c\$\\new$server.xml"; my $dstfile = "\\\\$drserver.$domain\\c\$\\new$server.xml"; copy($srcfile, $dstfile) or die "Copy failed: $!"; # Now we import the IIS setting to the DR box with the changes system("iiscnfg /s $drserver.$domain /import /f c:\\new$server.xml /sp + /lm /dp /lm /children"); # Here we go back through the XML file and start each instance using I +ISWEB my $inserver = 0; foreach my $newline (@file) { chomp $newline; if ($newline =~ /ServerBindings/i) { print "$newline\n"; $inserver = 1; } if (($newline =~ /ServerComment/i) and ($inserver == 1)) { my ($com, $inst) = split(/=/,$newline); system("iisweb /start $inst /s $drserver.$domain"); $inserver = 0; } }

In reply to IIS 6.0 Export and Import to Back Server by LostS

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.