Solved

Move IIS web site using script

Posted on 2010-08-31
5
737 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

623 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