Getting “Can't find the drive. The drive called 'IIS' does not exist.”

匿名 (未验证) 提交于 2019-12-03 02:00:02

问题:

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

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

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

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

回答1:

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

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 


回答2:

I had a simular problem. The mistake was that I was not running the script in Admin mode.



回答3:

On Windows Server 2008 32-bit, I had to explicitly download and install "IIS Powershell Snap-in (x86)" from Microsoft's website.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!