Powershell:如何在子文件夹下创建IIS 6虚拟目录/Web应用程序 [英] Powershell : How to create IIS 6 Virtual Directory/Web application under a Subfolder
问题描述
我试图使用Powershell在IIS 6网站的特定子文件夹下创建Web应用程序/VirtualDirectory,如下所示:
I am trying to create a Web application/VirtualDirectory under a specific subfolder of a IIS 6 website using Powershell as show below:
Test (website) ----------------> c:\InetPub
SubDirectory ------------------> ..\Subdirectory
gadgets (Web App) -----------------> ..\Gadgets
脚本
$WebSiteName = "Test"
$virtualDirName = "subdirectory\gadgets"
$appPoolName = "DefaultAppPool"
$VirtalDirHomePath = "c:\InetPub\Subdirectory\Gadgets"
$iisWebSite = Get-WmiObject "IISWebServerSetting" `
-Namespace "root\MicrosoftIISv2" `
-filter "ServerComment like '%$WebSiteName%'"
$virtualDirSettings = [wmiclass] "root\MicrosoftIISv2:IIsWebVirtualDirSetting"
$newVDir = $virtualDirSettings.CreateInstance()
$newVDir.Name = ($iisWebSite.Name + '/ROOT/' + $virtualDirName)
$newVDir.Path = $VirtalDirHomePath
$newVDir.Put();
$nvdir = $iisWebSite.Name + '/ROOT/' + $virtualDirName
$nvdir = $nvdir.Replace("\", "/")
$v = Get-WmiObject -Class IIsWebVirtualDir -Namespace root\microsoftiisv2 `
-filter "Name='$nvdir'"
#Create WebAppliction
$v.AppCreate3(2, $appPoolName, 1)
如果我用正斜杠路径分隔符(subdirectory/gadgets
)指定$virtualDirName
,则$newVDir.Put()
调用将引发以下异常
If I specify the $virtualDirName
with forward slash path separator (subdirectory/gadgets
) , $newVDir.Put()
call throws following exception
调用"Put"为"0"的异常 参数:"Win32:系统无法 找到指定的路径.
Exception calling "Put" with "0" argument(s): "Win32: The system cannot find the path specified.
如果我用反斜杠路径分隔符(子目录\小工具)更改$virtualDirName
,则$newVDir.Put()
调用将成功返回.
If I change the $virtualDirName
with backslash path separator (subdirectory\gadgets) $newVDir.Put()
call returns successfully.
我不确定这是否正确.
是否有更好的方法可以在特定子文件夹下创建Web应用程序/VirtualDirectory,以及如何列出在子文件夹下创建的VirtualDirectory/WebApplication.
Is there any better way to create Web Application/VirtualDirectory under a specific subfolder and How can I list VirtualDirectory/WebApplication created under a subfolder.
推荐答案
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%
请注意,virtualDirName
中的虚拟目录路径是使用正斜杠指定的.
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%
这篇关于Powershell:如何在子文件夹下创建IIS 6虚拟目录/Web应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!