Get-AzureRmResource:找不到与参数名称匹配的参数 'Tag'
Get-AzureRmResource : A parameter cannot be found that matches parameter name 'Tag'
所以我完全被这个难住了。
问题
我有一个 powershell 脚本(一个 .ps1 文件),它有时会执行以下操作:
Import-Module AzureRM
Login-AzureRmAccount -Credential $azureCredentials | out-null
Select-AzureRmSubscription -SubscriptionId $azureSubscriptionId -TenantId $azureTenantId | out-null
Write-Host (ConvertTo-Json((Get-AzureRmResource -Tag @{ "env"="dev"}) | Select Name, Location))
我通过执行以下操作在 .NET 控制台应用程序中 运行 脚本:
Dim process = New Process() With {.StartInfo = New ProcessStartInfo With {
.FileName = "powershell.exe",
.Arguments = "-ExecutionPolicy ByPass -file """ & _powershellScriptsPath & "\get-webapps.ps1",
.UseShellExecute = False,
.RedirectStandardOutput = True,
.RedirectStandardError = True
}}
该脚本在我的笔记本电脑上运行良好,无论是 运行 来自 ISE 还是来自控制台应用程序。
然后在我的桌面上,它在 ISE 中工作正常但在控制台应用程序中失败,并显示以下错误消息:
Get-AzureRmResource : A parameter cannot be found that matches parameter name 'Tag'.
我想不通。
一些见解
我的$PSVersionTable
在两台电脑上都是一样的:
Name Value
---- -----
PSVersion 5.1.17134.165
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.17134.165
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
我的笔记本电脑有 6.1.0 版的 AzureRm 模块:
PS C:\WINDOWS\system32> Get-InstalledModule -Name AzureRm
Version Name Repository Description
------- ---- ---------- -----------
6.1.0 AzureRM PSGallery Azure Resource Manager Module
虽然我的桌面版本是 6.5.0:
PS C:\WINDOWS\system32> Get-InstalledModule -Name AzureRm
Version Name Repository Description
------- ---- ---------- -----------
6.5.0 AzureRM PSGallery Azure Resource Manager Module
因此这里存在版本差异,但 -Tag 确实存在于 6.1.0 中,因为在 Powershell ISE 中脚本确实有效。它必须使用 6.1.0,因为它似乎是唯一安装的版本(?)。
控制台应用程序 运行 在两个 Visual Studios (laptop/desktop) 中的配置也是相同的(至少据我所知)。值得注意的是,它在两台计算机上都被编译为 32 位的 AnyCPU 和 运行s。
查看 this 似乎 -tag
缺少 6.0.0 之前的 AzureRm 版本。这是由以下内容确定的问题的根本原因:
get-command get-azurermresource -full
解决方法是升级该版本。你可以找到模块的位置:
get-module azurerm | select modulebase
ps。另一种解决方法是使用 odata 查询:
Get-AzureRmResource -ODataQuery "`$filter=tagname eq 'something'"
所以我完全被这个难住了。
问题
我有一个 powershell 脚本(一个 .ps1 文件),它有时会执行以下操作:
Import-Module AzureRM
Login-AzureRmAccount -Credential $azureCredentials | out-null
Select-AzureRmSubscription -SubscriptionId $azureSubscriptionId -TenantId $azureTenantId | out-null
Write-Host (ConvertTo-Json((Get-AzureRmResource -Tag @{ "env"="dev"}) | Select Name, Location))
我通过执行以下操作在 .NET 控制台应用程序中 运行 脚本:
Dim process = New Process() With {.StartInfo = New ProcessStartInfo With {
.FileName = "powershell.exe",
.Arguments = "-ExecutionPolicy ByPass -file """ & _powershellScriptsPath & "\get-webapps.ps1",
.UseShellExecute = False,
.RedirectStandardOutput = True,
.RedirectStandardError = True
}}
该脚本在我的笔记本电脑上运行良好,无论是 运行 来自 ISE 还是来自控制台应用程序。
然后在我的桌面上,它在 ISE 中工作正常但在控制台应用程序中失败,并显示以下错误消息:
Get-AzureRmResource : A parameter cannot be found that matches parameter name 'Tag'.
我想不通。
一些见解
我的$PSVersionTable
在两台电脑上都是一样的:
Name Value
---- -----
PSVersion 5.1.17134.165
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.17134.165
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
我的笔记本电脑有 6.1.0 版的 AzureRm 模块:
PS C:\WINDOWS\system32> Get-InstalledModule -Name AzureRm
Version Name Repository Description
------- ---- ---------- -----------
6.1.0 AzureRM PSGallery Azure Resource Manager Module
虽然我的桌面版本是 6.5.0:
PS C:\WINDOWS\system32> Get-InstalledModule -Name AzureRm
Version Name Repository Description
------- ---- ---------- -----------
6.5.0 AzureRM PSGallery Azure Resource Manager Module
因此这里存在版本差异,但 -Tag 确实存在于 6.1.0 中,因为在 Powershell ISE 中脚本确实有效。它必须使用 6.1.0,因为它似乎是唯一安装的版本(?)。
控制台应用程序 运行 在两个 Visual Studios (laptop/desktop) 中的配置也是相同的(至少据我所知)。值得注意的是,它在两台计算机上都被编译为 32 位的 AnyCPU 和 运行s。
查看 this 似乎 -tag
缺少 6.0.0 之前的 AzureRm 版本。这是由以下内容确定的问题的根本原因:
get-command get-azurermresource -full
解决方法是升级该版本。你可以找到模块的位置:
get-module azurerm | select modulebase
ps。另一种解决方法是使用 odata 查询:
Get-AzureRmResource -ODataQuery "`$filter=tagname eq 'something'"