Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get-AzureRmApiManagementSubscription ByProduct does not return same Type consistently #4676

Closed
solankisamir opened this issue Sep 27, 2017 · 2 comments
Assignees
Labels
API Management Service Attention This issue is responsible by Azure service team.

Comments

@solankisamir
Copy link
Member

solankisamir commented Sep 27, 2017

Cmdlet(s)

Get-AzureRmApiManagementSubscription

PowerShell Version

4.4.0

Module Version

AzureRm.ApiManagement

OS Version

Any

Description

The Cmdlet based on description should always return an IList.
But it actually varies based on content.

Debug Output

Instructions: to get Debug Output, set $DebugPreference="Continue" and then execute the cmdlet or script causing the issue

Script/Steps for Reproduction

Below we can see since Product 58a4aeac497000007d060002 contains multiple subscriptions, then the output is Array. But if the product like 58a4aeac497000007d060001 contains just one Subscription, the output is PsApiManagementSubscription

PS C:\WINDOWS\system32> $result = Get-AzureRmApiManagementSubscription -Context $context -ProductId 58a4aeac497000007d060002
PS C:\WINDOWS\system32> $result.GetType()

True True Object[] System.Array

PS C:\WINDOWS\system32> $result = Get-AzureRmApiManagementSubscription -Context $context -ProductId 58a4aeac497000007d060001
PS C:\WINDOWS\system32> $result.GetType()

True False PsApiManagementSubscription System.Object

@solankisamir
Copy link
Member Author

The advice is to always enumerate collections in your output (i.e. WriteOuput(myCollection, true). PowerShell automatically unwraps single object collections returned as output. For cmdlets that can return both a single object or a list of objects, you can include bot the object type and the enumerable (i.e. OutputType(typeof(foo), typeof(IList)), you can also use the optional string parameter to associate these with parameter sets, as described here: https://msdn.microsoft.com/en-us/library/ee857075(v=vs.85).aspx

solankisamir added a commit to solankisamir/azure-powershell that referenced this issue Oct 23, 2017
* Updated documentation for issue
Azure#4676
@solankisamir
Copy link
Member Author

Closing with reason above.

@bsiegel bsiegel added the Service Attention This issue is responsible by Azure service team. label Sep 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Management Service Attention This issue is responsible by Azure service team.
Projects
None yet
Development

No branches or pull requests

2 participants