Currently using TFS 2015 update 3 for deployments and I have added "PowerShell on target machine" task, which calls for PowerShell script saved on IIS server to stop website before deployments:
icm -ComputerName $server -ScriptBlock {Import-Module WebAdministration; Stop-Website -Name $app}
with session variables as: $server = abc.xyz.com
, $app = DefaultWebSite
The error I get is:
The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: Cannot validate argument on parameter 'Name'. The argument is null. Provide a valid value for the argument, and then try running the command again.”
The same script works if I hard code the server & application name.
使用脚本块时,除非将param
与参数列表一起使用,或者将PowerShell与3+版本一起使用using:
scope修饰符,否则无法使用脚本作用域中的变量。
icm -ComputerName $server -ScriptBlock {Import-Module WebAdministration; Stop-Website -Name $using:app}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.