Solved

Move IIS web site using script

Posted on 2010-08-31
5
726 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
Comment Utility
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
Comment Utility

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
Comment Utility
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
Comment Utility
"website.Site" is the name of your website, you can edit this aswell
0
 

Author Closing Comment

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

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Article by: kevp75
Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now