【问题标题】:New-Item Behavior Changes When Using Runspace to Run Command Remotely使用运行空间远程运行命令时的新项目行为更改
【发布时间】:2018-05-22 04:57:24
【问题描述】:

我正在使用 VB.Net 使用 WSManConnectionInfo 打开 Powershell 运行空间。连接工作正常。我正在尝试运行 New-Item 命令以创建新的虚拟目录。

New-Item "IIS:\Sites\ExternalInventory FTP\TestVT"  -Type VirtualDirectory -physicalPath "C:\"

该命令在服务器本地运行时运行良好。但是,当通过运行空间远程运行时,出现错误:

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

我最初尝试使用New-WebVirtualDirectory 命令创建虚拟目录,但这导致了其他错误。我需要使用New-Item

是什么导致了 New-Item 命令的行为差异,如何使用它通过运行空间创建新的虚拟目录?

注意:我已经通过运行空间尝试了其他命令,它们似乎按预期工作。

编辑

我知道 New-Item 命令没有文档中列出的参数“physicalPath”:https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/new-item?view=powershell-6

New-Item 命令在文档中的多个位置用于创建具有physicalPath 参数的虚拟目录。查看链接

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/new-item?view=powershell-6

https://forums.iis.net/t/1223546.aspx?New+WebVirtualDirectory+does+not+work+when+invoked+remotely+and+a+UNC+path+is+used

【问题讨论】:

  • New-Item 没有 -PhysicalPath 参数。
  • 抱歉,我正在编辑以包含该内容。请查看我的编辑。另外,为什么该命令会在本地使用-PhysicalPath 参数?
  • 这是一个错误的论坛帖子链接。我怀疑它可以在本地工作,因为它使用的是 IIS: 驱动器,并且对 *-Item cmdlet 的支持取决于您使用的驱动器。
  • 文档链接也错了? PS IIS:\Sites> New-Item iis:\Sites\TestSite -bindings @{protocol="http";bindingInformation=":80:TestSite"} -physicalPath c:\test 引用自他们使用该命令的文档:“使用 -physicalPath 参数非常简单。但您可能会问自己,为什么 -bindings 参数看起来如此复杂。”
  • 我在文档的任何地方都找不到该示例。

标签: vb.net powershell powershell-remoting


【解决方案1】:

正如 cmets 中所指出的,我需要在我的脚本中包含 WebAdministration 模块。

感谢 TheMadTechnitian

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-23
    • 2020-09-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多