Powershell : How to create IIS 6 Virtual Directory/Web application under a Subfolder

后端 未结 2 1173
被撕碎了的回忆
被撕碎了的回忆 2021-01-19 10:45

I am trying to create a Web application/VirtualDirectory under a specific subfolder of a IIS 6 website using Powershell as show below:

IIS WebSite Structure <&

相关标签:
2条回答
  • 2021-01-19 11:31

    Give this a try. It connects to the root of website 1 (Default Website). Creates a IIsWebDirectory object for the gadgets folder and assigns it an application pool.

    $root = [adsi] "IIS://localhost/W3SVC/1/ROOT"
    $vDir = $root.Create("IIsWebDirectory", "SubDirectory\Gadgets")
    $vDir.AppCreate3(2, "DefaultAppPool", $false)
    $vDir.AppFriendlyName = "Andy Test"
    $vDir.SetInfo()
    

    If you need to connect to a website other than the default web site you can get the ID of the website with this command:

    ([adsi] "IIS://localhost/W3SVC").psbase.Children | ? {$_.psbase.schemaclassname -eq "IIsWebServer" } | select Path, ServerComment
    

    Output:

    Path                         ServerComment
    ----                         -------------
    IIS://localhost/W3SVC/1      {Default Web Site}
    IIS://localhost/W3SVC/2      {WHS site}
    
    0 讨论(0)
  • 2021-01-19 11:33

    An alternative solution to create a virtual directory in IIS 6.0 through scripting, which doesn't involve PowerShell, is to use the iisvdir.vbs script:

    SET webSiteName=Test
    SET virtualDirName=subdirectory/gadgets
    SET virtualDirHomePath=C:\InetPub\Subdirectory\Gadgets
    
    cscript %SystemRoot%\system32\iisvdir.vbs /create %webSiteName% %virtualDirName% %virtualDirHomePath%
    

    Note that the virtual directory path in virtualDirName is specified using forward slashes.

    You can also list the virtual directories in a specific path using the same iisvdir.vbs script:

    cscript %SystemRoot%\system32\iisvdir.vbs /query %webSiteName%/%virtualDirName%
    
    0 讨论(0)
提交回复
热议问题