Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

change physical path for virtual directory or site in IIS using command line for IIs6 or IIs7

I need to implement some versioning for deployment for the app I support where I can copy the site to say c:\inetpub\wwwroot\app_v2 and then switch the virtual directory from c:\inetpub\wwwroot\app_v1.

Is there a way to change the physical path for a virtual directory in IIS from the command line?

Edit:

i found that in IIS7 you can use appcmd to set the physical path of a virtual directory using this format on this page Change the Physical Path of Virtual Directory Content. I was looking for something more universal....

appcmd set vdir /vdir.name:string /physicalPath:string

However, there doesnt seem to be an equivelant for IIS 6.

like image 613
MikeJ Avatar asked Mar 19 '09 18:03

MikeJ


2 Answers

Yes, look at WMI scripting.

http://learn.iis.net/page.aspx/163/managing-applications-and-application-pools-on-iis-7-with-wmi/

http://www.aspfree.com/c/a/IIS/IIS-60-Getting-Information-Using-WMI/3/

Nick

like image 106
Nick Bolton Avatar answered Sep 21 '22 19:09

Nick Bolton


I had the same question today: "how do you change the path to an IIS6 vdir using the command line?"

WMI scripting was the way to go, so i figured i'd post the vbs that i created for this.

To use it just pass the vdir name and path. So if I had a vdir called "Web" and wanted to change the path to "d:\theNewPath\to\Website", then I would run the following command in the command prompt:

updateVDirPath web d:\theNewPath\to\Website

Also, to check the path of the Vdir, just pass the vdir name:

updateVDirPath web

Here are the contents to updateVDirPath.vbs

If WScript.Arguments.Count = 0 or WScript.Arguments.Count > 2  Then
    WScript.Echo "To check the vDirs path, call updateVDirPath <vDir>" & vbCrLf & "To update the vDir's path, call updateVDirPath <vDir> <newPath>"
Else
    set providerObj = GetObject("winmgmts://localhost/root/MicrosoftIISv2") 
    set IIsWebVirtualDirSettingObj = providerObj.get("IIsWebVirtualDirSetting='W3SVC/1/ROOT/" & WScript.Arguments(0) & "'") 

    If WScript.Arguments.Count = 1 Then
        WScript.Echo "Current path is: " & IIsWebVirtualDirSettingObj.Path
    Else
        IIsWebVirtualDirSettingObj.Path = WScript.Arguments(1)
        IIsWebVirtualDirSettingObj.Put_ () 
    End If
End If
like image 36
jcj80 Avatar answered Sep 22 '22 19:09

jcj80