2014-06-24 58 views
27

我寫了一個PowerShell腳本來自動部署IIS網站,但是當我傳遞參數給腳本,我得到了以下錯誤:「找不到驅動器,名爲'IIS'的驅動器不存在。」

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

我的腳本(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])) 
     } 
    ....... 

請讓我知道爲什麼子命令set-location IIS:\;在命令Invoke-Command是不被認可?

回答

53

驅動器,而不是驅動器r。該驅動器由WebAdministration模塊提供,因此您需要首先安裝/導入該模塊。

您如何安裝模塊取決於您的實際系統以及您是否使用GUI或PowerShell。在Windows Server 2008 R2中,例如,你想安裝該模塊具有以下PowerShell命令:安裝模塊

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

後,你可以在你的腳本加載這樣的:

Import-Module WebAdministration 
+0

我已經安裝了IIS-snapin.And命令包含三個子命令:「Import-Module WebAdministration; set-location IIS:\;(Stop-Website $($ websiteName [$ j]))」用分號分割。現在問題是「set-location IIS:\」無法識別。 – user3772170

+0

這意味着如果U鍵在下面的命令中,U會得到相同的錯誤:Invoke-Command -ComputerName xx.xx.xx.xx -ScriptBlock {C:\ Windows \ System32 \ WindowsPowerShell \ v1.0 \ powershell.exe - 命令Import-Module WebAdministration; set-location IIS:\; Stop-Website testsite} – user3772170

+0

@ user3772170:您正在遠程主機上運行命令,因此該模塊必須安裝在該主機上。此外,您的代碼已經在PowerShell中運行,因此在腳本塊中不需要「C:\ Windows \ System32 \ WindowsPowerShell \ v1.0 \ powershell.exe -command」。刪除。 –

25

我有一個相似的問題。錯誤是我沒有在Admin模式下運行腳本。

+1

老兄,你搖滾! – Quantium

+1

如果您正在開發腳本,PowerShell ISE也是如此。 – PhilDulac

1

在Windows Server 2008 32位上,我必須從Microsoft網站上明確下載並安裝「IIS Powershell Snap-in(x86)」。

相關問題