PowerShell script to migrate FTP virtual directories from Metabase.xml of IIS 6 to PowerShell commands for IIS 7.5


You have a thousands of FTP virtual directories in IIS 6. Now you would like to migrate these to IIS 7.5. There is a tool called Web Deploy which would help you migrate WebSites but unfortunately that doesn't migrate FTP Site and its virtual directories.

So we worked upon a PowerShell script which can help you help you migrate FTP websites and virtual directories with very basic settings. You can modify this script to do more while migrating like username and others..

 

In order to run the script you need Metabase.xml file from Windows 2003 box. You can find this file in %SystemRoot%\system32\inetsrv folder. Please open Metabase.xml file in notepad and remove <configuration> tab from the top and bottom of document. Once done, run below script :

# Remove the following lines from the XML source file before running this 
# <configuration xmlns="urn:microsoft-catalog:XML_Metabase_V64_0">
# </configuration

# Developed under Powershell V2 on 2008 R2
# invoke "importsystemmodules" to get the webAdministration libraries loaded

#importsystemmodules
select-xml -path d:\temp\MetaBase.xml -xpath "//IIsFtpVirtualDir" | % { 
    $location= split-path $_.node.getattribute("Location") -leaf 
    $path = $_.node.getattribute("Path") 

     
        # Use this to test, this will give you stack of commands to execute which you can validate, add or modify and create another script file.
     "New-WebVirtualDirectory -site 'Default FTP Site' -name '$location' -physicalpath `"$path`" -Force"  # | out-file -append c:\temp\junk.txt.xml 

    # Use this to really create on IIS if you are sure (backup first)
    # "New-WebVirtualDirectory -site 'Default FTP Site' -name $location -physicalpath `"$path`"" 

This script can create commands which you can validate and run after, Or you can directly run. You need to uncomment the lines accordingly in above script. DISCLAIMER: THE MATERIALS ARE PROVIDED "AS IS" WITHOUT ANY EXPRESS OR IMPLIED WARRANTY OF ANY KIND.

 

 ~Devendra Asane

 

createFTP.ren2ps1.txt

Comments (6)
  1. Rich says:

    In that I'm not a PowerShell guru, can you please expand on the script that you've provided?

    Thank you in advance.

  2. Janardhan says:

    Hi Devendra,

                     How do I migrate FTP virtual directories Under FTP Virual directories to IIS7.5?(FTP Site/Vir Dir/Vir Dir)

    Thanks

  3. Dennis says:

    What happened to the script?  I have tried using the script but the virtual directories do not get created.

  4. @Deniis : you may need to uncomment the last line if you would like to create the VDs right when script ran. In present form this script would generate VD create command text at console. This text you can run later to create VD's after validating it.

  5. ivy says:

    Davendra,

    Thanks for this but I cannot find the script here, Is there suppose to be a script in createFTP.ren2ps1.txt  ?

  6. Hector Rios says:

    Hello i want to complement this, i used and save me a lot of time. just some addendums.

    First the data copy, the directories must exist to have this as successful, if you execute this with non exisiting directories, you will have errors regarding not existen path.

    second you have to remove quotation marks on the command, other way is just lising on the screen but not executing.

    third bracket key at the end was missing.

    here is the script modified, is working

    # Do not forget to Remove the following lines from the XML source file before running this

    # <configuration xmlns="urn:microsoft-catalog:XML_Metabase_V64_0">

    # </configuration>

    # Developed under Powershell V2 on 2008 R2

    # invoke "importsystemmodules" to get the webAdministration libraries loaded

    #importsystemmodules

    select-xml -path d:tempMetaBase.xml -xpath "//IIsFtpVirtualDir" | % {

       $location= split-path $_.node.getattribute("Location") -leaf

       $path = $_.node.getattribute("Path")

           # Use this to test, this will give you stack of commands to execute which you can validate, add or modify and create another script file.

        #"New-WebVirtualDirectory -site 'Default FTP Site' -name '$location' -physicalpath `"$path`" -Force"  # | out-file -append c:tempjunk.txt.xml

       # Use this to really create on IIS if you are sure (backup first)

    New-WebVirtualDirectory -site 'Nane of your site, not always is default ftp site' -name $location -physicalpath `"$path`"

    }

Comments are closed.

Skip to main content