获取“无法找到驱动器。称为“IIS”的驱动器不存在。 [英] Getting "Can't find the drive. The drive called 'IIS' does not exist."

查看:925
本文介绍了获取“无法找到驱动器。称为“IIS”的驱动器不存在。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I wrote a PowerShell script to deploy IIS Website automatically, but when I pass parameters to the script I get the following error:


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

Cannot find the drive. The drive called 'IIS' does not exist.

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

My script (iss_website_version_update.ps1) is as below, but note that it is not finished yet:

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]))
        }
    .......

请让我知道为什么子命令 set-location IIS:\; in th e命令无法识别Invoke-Command

Please let me know why the sub-command set-location IIS:\; in the command Invoke-Command is not be recognized ?

推荐答案

Drive,不开车 r 。该驱动器由 WebAdministration 模块提供,因此您需要先安装/导入该模块。

Drive, not Driver. The drive is provided by the WebAdministration module, so you need to install/import that module first.

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

How you install the module depends on your actual system and whether you use GUI or PowerShell. On a Windows Server 2008 R2 for instance you'd install the module with the following PowerShell commands:

Import-Module ServerManager
Add-WindowsFeature Web-Scripting-Tools

安装模块后,您可以将其加载到您的像这样的脚本:

After the module is installed you can load it in your script like this:

Import-Module WebAdministration

这篇关于获取“无法找到驱动器。称为“IIS”的驱动器不存在。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆