Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Move IIS web site using script

Posted on 2010-08-31
5
Medium Priority
?
742 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 1000 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 1000 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

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.
What You Need to Know when Searching for a Webhost Provider
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…

783 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