使用powershell将虚拟目录添加到Windows 10中的IIS站点

使用powershell将虚拟目录添加到Windows 10中的IIS站点,powershell,iis,Powershell,Iis,我尝试通过两种方式添加虚拟目录: 1º试 PS C:\>New-WebVirtualDirectory -Site "Default Web Site" -Name ContosoVDir -PhysicalPath C:\inetpub\contoso 2º试 ## Settings $siteName = 'Default Web Site' $virtualDirectoryName = 'Test' $physicalPath = 'C:\OtherDir' ## Init $

我尝试通过两种方式添加虚拟目录:

1º试

PS C:\>New-WebVirtualDirectory -Site "Default Web Site" -Name ContosoVDir -PhysicalPath C:\inetpub\contoso
2º试

## Settings
$siteName = 'Default Web Site'
$virtualDirectoryName = 'Test'
$physicalPath = 'C:\OtherDir'

## Init
$virtualDirectoryPath = "IIS:\Sites\$siteName\$virtualDirectoryName"

New-Item $virtualDirectoryPath -type VirtualDirectory -physicalPath $physicalPath
两种方式都会引发此错误:

找不到与参数名称“physicalPath”匹配的参数


我已经在Windows 10和Windows Server 2012 R2上试用过它。

新的WebVirtualDirectory
将PhysicalPath作为参数。。不是新项目。使用
新WebVirtualDirectory
时会出现什么错误?参数-PhysicalPath的目录必须是现有目录,并且该命令需要在具有足够权限的用户帐户下运行(例如,我使用“以管理员身份运行”启动PowerShell以测试新WebVirtualDirectory)安德烈·莫尔顿是完全正确的。我的错误是在没有管理员权限的情况下运行powershell。我迷路了,因为错误没有提到任何关于权限的内容。。。非常感谢。@toscanelli这很奇怪,如果我在没有足够权限的情况下尝试,我会收到一条错误消息,以“进程应该具有提升状态才能访问IIS配置数据”开头。可能在某些地方存在版本差异。
New WebVirtualDirectory
将PhysicalPath作为参数。。不是新项目。使用
新WebVirtualDirectory
时会出现什么错误?参数-PhysicalPath的目录必须是现有目录,并且该命令需要在具有足够权限的用户帐户下运行(例如,我使用“以管理员身份运行”启动PowerShell以测试新WebVirtualDirectory)安德烈·莫尔顿是完全正确的。我的错误是在没有管理员权限的情况下运行powershell。我迷路了,因为错误没有提到任何关于权限的内容。。。非常感谢。@toscanelli这很奇怪,如果我在没有足够权限的情况下尝试,我会收到一条错误消息,以“进程应该具有提升状态才能访问IIS配置数据”开头。也许某个地方的版本有所不同。