【发布时间】:2018-04-16 08:36:51
【问题描述】:
我有一个 PowerShell 脚本,我打算将其用作 Bamboo 中的部署步骤。打开 PowerShell 并使用 ./script.ps1 运行脚本可以正常工作,但使用 powershell.exe -command ./script.ps1 失败并出现错误 Unable to find type [Microsoft.PowerShell.Commands.WebRequestMethod]。
直接从 PowerShell 运行脚本和使用 powershell.exe -command 有什么区别?我错过了什么?
有关问题的 MWE:
function Test-RestMethod {
param([string]$Uri, [Microsoft.PowerShell.Commands.WebRequestMethod] $Method = 'Get')
$result = Invoke-RestMethod $uri -Method $Method
return $result
}
Test-RestMethod -Uri https://blogs.msdn.microsoft.com/powershell/feed/ -Method 'Get' | Format-Table -Property Title, pubDate
【问题讨论】:
-
我猜你的 powershell 路径正在返回一个不同的版本,尝试使用 Get-Host 来确定每种方法使用的版本。
-
它们都使用相同的版本,在相同的架构上(都是 64 位 PowerShell v5.1.14393.1198)。
标签: powershell bamboo