Solved

Move IIS web site using script

Posted on 2010-08-31
5
735 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

726 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