获取"无法找到驱动器.名为'IIS'的驱动器不存在."

Jia*_*Xia 37 iis powershell namespaces

我编写了一个PowerShell脚本来自动部署IIS网站,但是当我将参数传递给脚本时,我收到以下错误:

找不到驱动器.名为"IIS"的驱动器不存在.

我的脚本(iss_website_version_update.ps1)如下所示,但请注意它还没有完成:

param(
[array]$iishostlist=$(throw "Parameter missing: -name iishostlist"),
[array]$websiteName=$(throw "Parameter missing: -name websiteName")
)

For($i=0;$i -lt $iishostlist.Count; $i++){
For($j=0;$j -lt  $websiteName.Count; $j++){
    $start = get-date
    $tempSession = new-pssession  -ComputerName  $($iishostlist[$i])
    Invoke-Command -Session $tempSession -ScriptBlock {
        C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NonInteractive -command Import-Module WebAdministration;set-location IIS:\;(Stop-Website $($websiteName[$j]))
        }
    .......
Run Code Online (Sandbox Code Playgroud)

请让我知道为什么命令set-location IIS:\;中的子命令 Invoke-Command不被识别?

Ans*_*ers 70

驾驶,而不是驾驶r.驱动器由WebAdministration模块提供,因此您需要先安装/导入该模块.

如何安装模块取决于您的实际系统以及您是使用GUI还是PowerShell.例如,在Windows Server 2008 R2上,您将使用以下PowerShell命令安装该模块:

Import-Module ServerManager
Add-WindowsFeature Web-Scripting-Tools
Run Code Online (Sandbox Code Playgroud)

安装模块后,您可以在脚本中加载它,如下所示:

Import-Module WebAdministration
Run Code Online (Sandbox Code Playgroud)

  • 此外,请确保您使用管理员权限运行脚本.那是我的错误...... (2认同)

azu*_*eca 44

解决方案在管理模式下解析运行脚本(或powershell shell/exe).

  • 如果您正在开发脚本,PowerShell ISE也是如此. (4认同)
  • 杜德,你摇滚! (2认同)

小智 5

对于那些在 windows server 2016 和 2019 上的人,我发现它是服务器功能

IIS 管理控制台又名 Web-Mgmt-Console

需要打开。如果您处于活动的 powershell 会话中并且已导入 WebAdministration 模块和命令

Get-PSDrive 
Run Code Online (Sandbox Code Playgroud)

不在列表中返回 IIS。运行以下

Remove-Module WebAdministration
Import-Module WebAdministration
Get-PSDrive
Run Code Online (Sandbox Code Playgroud)

然后您应该会看到powershell IIS 驱动器。我怀疑我的问题与运行脚本有关,这些脚本导入了 WebAdministration 但在我的 powershell 会话中附加了 PSDrive IIS。除非我先将其删除,否则再次尝试导入 WebAdministration 不会将 PSDrive 附加到我的会话。

  • 这在 Win 10 Pro 上对我不起作用。缺少其他一些步骤或功能。 (2认同)