Solved

Move IIS web site using script

Posted on 2010-08-31
5
732 Views
Last Modified: 2012-05-10
I would like to move an existing iis website to another location/folder on the same server.  Does anyone know how this would be possible using a script?
0
Comment
Question by:Defianse
  • 2
  • 2
5 Comments
 
LVL 9

Expert Comment

by:shalabhsharma
ID: 33573630
Try web developnet tool with Web Deployment Tool it is easier to manage, deploy, and migrate  web servers.

    * Ability to synchronize or migrate the entire Web server, or a single Web site or application.
    * Synchronizes only data that has changed.
    * Ability to detect missing dependencies during synchronization.
    * Automatically gathers the following when you sync a Web site:
          o Content
          o IIS configuration
          o Certificates
          o Registry keys
          o ASP.NET configuration
    * Use a secure service (server administrators only, can be secured with HTTPS, etc.) to synchronize the machines.

http://learn.iis.net/page.aspx/715/use-the-web-deployment-tool
0
 
LVL 9

Accepted Solution

by:
shalabhsharma earned 250 total points
ID: 33573714

Script to modify the physical path of the root application:

' Connect to the WMI WebAdministration namespace.
Set oWebAdmin = GetObject("winmgmts:root\WebAdministration")
' Get the root virtual directory for the default Web site.
Set oVDir = oWebAdmin.Get(_
"VirtualDirectory.SiteName='Default Web Site',ApplicationPath='/',Path='/'")

' Set the physical path for the default Web site.
oVDir.PhysicalPath = "C:\MyContent"
oVDir.Put_

 Enumerating virtual directories , the root virtual directory's path of an application is "/".

' Connect to the WMI WebAdministration namespace.
Set oWebAdmin = GetObject("winmgmts:root\WebAdministration")

' Use InstancesOf to retrieve the VirtualDirectories, you can also retrieve applications by using InstancesOf("Application").
Set oDirs = oWebAdmin.InstancesOf("VirtualDirectory")

' Iterate through the VirtualDirectories.
For Each oDir In oDirs
WScript.Echo "  Web site/Application: " & oDir.SiteName & oDir.ApplicationPath  
Wscript.Echo "  virtual directroy:    " & oDir.Path
Wscript.Echo "  physical path:        " & oDir.PhysicalPath
WScript.Echo
Next

0
 
LVL 16

Assisted Solution

by:Stephan
Stephan earned 250 total points
ID: 33574361
You can use this by the following code in C#

Be sure to add System.DirectoryServices to your references.
DirectoryEntry w3svc = new DirectoryEntry(String.Format("IIS://{0}/W3SVC/{1}", Environment.MachineName, "ID of the site"));
            w3svc.Properties["ServerComment"].Value = website.Site;
            w3svc.CommitChanges();
            DirectoryEntry directory = new DirectoryEntry(String.Format("IIS://{0}/W3SVC/{1}/Root", Environment.MachineName, "ID of the site"));
            directory.Properties["Path"][0] = "C:\websitelocation";
            directory.CommitChanges();

Open in new window

0
 
LVL 16

Expert Comment

by:Stephan
ID: 33574365
"website.Site" is the name of your website, you can edit this aswell
0
 

Author Closing Comment

by:Defianse
ID: 33578971
I know I only asked for help with scripting but the C# code is a huge and welcome bonus!
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On July 14th 2015, Windows Server 2003 will become End of Support, leaving hundreds of thousands of servers around the world that still run this 12 year old operating system vulnerable and potentially out of compliance in many organisations around t…
Lync server 2013 or Skype for business Backup Service Error ID 4049 – After File Share Migration
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

827 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question