如何使用PowerShell v2.0在IIS 6.0中将创建的虚拟目录作为应用程序

时间:2010-08-27 06:45:15

标签: powershell

我在iis中使用以下代码

创建了一些虚拟目录
Function InputBox ($message, $title, $default)
{
    [void][reflection.assembly]::loadwithpartialname("microsoft.visualbasic")
    $result = [microsoft.visualbasic.interaction]::InputBox($message,$title, $default)

    return $result
}

$server=inputbox("enter the name of the server")
$iis=[adsi]"IIS://$($server)/W3SVC/1/Root"
$vdirname=inputbox("enter the name of virtual directory","","")
$vd = $iis.psbase.children.Add($vdirname,"IISWebVirtualDir")
$vdirpath=inputbox("enter the physical location of the application")
$vd.put("Path",$vdirpath)
$vd.psbase.CommitChanges()

但我无法将其创建为应用程序 任何人都可以帮助我解决这个问题。 要创建它作为应用程序,我将进入虚拟目录的属性,并在应用程序会话的虚拟工具选项卡中,单击“创建”按钮,然后创建应用程序。

任何人都可以帮助我使用将创建应用程序的powershell代码 谢谢, 拉穆克纳瓦普

2 个答案:

答案 0 :(得分:1)

使用PowerShell 2.0附带的WebAdministration模块:

Import-Module WebAdministration
New-WebVirtualDirectory -Site "Default Web Site" -Name ContosoVDir `
                        -PhysicalPath c:\inetpub\contoso

如果你复制/粘贴这个,请确保在行继续符后面没有额外的空格 - (`)。

答案 1 :(得分:0)