Reputation: 403
So I'm totally stumped by this one.
I have a powershell script (a .ps1 file) which at some point does the following:
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))
I run the script in a .NET console app by doing the following:
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
}}
The script works fine on my laptop, whether it's run from the ISE or from the console app.
Then on my desktop, it works fine in ISE but fails in the console app, with the following error message:
Get-AzureRmResource : A parameter cannot be found that matches parameter name 'Tag'.
I can't figure this out.
My $PSVersionTable
is the same on both computers:
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
My laptop has version 6.1.0 of the AzureRm module:
PS C:\WINDOWS\system32> Get-InstalledModule -Name AzureRm
Version Name Repository Description
------- ---- ---------- -----------
6.1.0 AzureRM PSGallery Azure Resource Manager Module
While my desktop has version 6.5.0:
PS C:\WINDOWS\system32> Get-InstalledModule -Name AzureRm
Version Name Repository Description
------- ---- ---------- -----------
6.5.0 AzureRM PSGallery Azure Resource Manager Module
So there is a difference of versions here but -Tag does exist in 6.1.0 because in Powershell ISE the script does work. And it has to use 6.1.0 since it seems to be the only version that is installed(?).
Also the console app runs the same configuration in both Visual Studios (laptop/desktop) (at least as far as I can tell). Notably it's compiled as AnyCPU and runs in 32bit on both computers.
Upvotes: 1
Views: 3012
Reputation: 72151
Looking at this it seems like -tag
is missing pre 6.0.0 version of AzureRm. That is the root cause of the issue identified by:
get-command get-azurermresource -full
workaround would be to upgrade that version. you can find where the module is by doing:
get-module azurerm | select modulebase
ps. another workaround would be to use odata query:
Get-AzureRmResource -ODataQuery "`$filter=tagname eq 'something'"
Upvotes: 3