我寫了一個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
是不被認可?
我已經安裝了IIS-snapin.And命令包含三個子命令:「Import-Module WebAdministration; set-location IIS:\;(Stop-Website $($ websiteName [$ j]))」用分號分割。現在問題是「set-location IIS:\」無法識別。 – user3772170
這意味着如果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
@ user3772170:您正在遠程主機上運行命令,因此該模塊必須安裝在該主機上。此外,您的代碼已經在PowerShell中運行,因此在腳本塊中不需要「C:\ Windows \ System32 \ WindowsPowerShell \ v1.0 \ powershell.exe -command」。刪除。 –