-
Notifications
You must be signed in to change notification settings - Fork 4k
Fix returned fields in Get-AzureRmSubscription docs #4941
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
Conversation
Fixed the examples of returned fields in Get-AzureRmSubscription. Added an extra piped statement to Example 4 because it would not naturally work with the newly renamed fields.
Can one of the admins verify this patch? |
Hi @cormacpayne, how does this look? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SteGriff Hey Stephen, thanks for making this change! This is exactly what needed to be one
``` | ||
|
||
This command gets all subscriptions in the current tenant that are | ||
authorized for the current user. | ||
|
||
### Example 4: Change the current context to use a specific subscription | ||
``` | ||
PS C:\>Get-AzureRmSubscription -SubscriptionId "xxxx-xxxx-xxxx-xxxx" -TenantId "yyyy-yyyy-yyyy-yyyy" | Set-AzureRmContext | ||
PS C:\>Get-AzureRmSubscription -SubscriptionId "xxxx-xxxx-xxxx-xxxx" -TenantId "yyyy-yyyy-yyyy-yyyy" | Select @{n='SubscriptionId';e={$_.Id}} | Set-AzureRmContext |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SteGriff the Set-AzureRmContext
cmdlet accepts a PSAzureSubscription
object from the pipeline for the SubscriptionObject
parameter. Any reason you want to change it to pass the SubscriptionId
to Set-AzureRmContext
instead? (this is just out of curiosity; I actually didn't know about the Select @{n=<name>;e=<expression>}
trick
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My experience of the command as written is that it doesn't work. Here's what happens for me, maybe you can verify?
# Outputs my context unchanged. The subscription is not switched, no error:
Get-AzureRmSubscription -SubscriptionId xxxx -TenantId yyyy | Set-AzureRmContext
# Capturing the object specifically and passing it as context throws error:
$ctx = Get-AzureRmSubscription -SubscriptionId xxxx -TenantId yyyy
Set-AzureRmContext -Context $ctx
Set-AzureRmContext : Cannot bind parameter 'Context'. Cannot convert the "8d6daea2-6038-4360-89a9-9944afa3ff6d"
value of type "Microsoft.Azure.Commands.Profile.Models.PSAzureSubscription" to type
"Microsoft.Azure.Commands.Profile.Models.PSAzureContext".
At line:1 char:29
+ Set-AzureRmContext -Context $ctx
+ ~~~~
+ CategoryInfo : InvalidArgument: (:) [Set-AzureRmContext], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.Azure.Commands.Profile.SetAzureRMContextCo
mmand
Maybe I'm being stupid but this pipe has never worked for me. I have also tried Select-AzureRmSubscription
at the end and it behaves the same. That's why I've gotten the habit of extracting the SubscriptionId
specifically.
Perhaps we're straying into the territory of another issue and I should just put the sample the way you have said?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, so Get-AzureRmSubscription
doesn't return a PSAzureContext
, it returns a PSAzureSubscription
, so you'll need to use the SubscriptionObject
parameter instead of the Context
parameter:
$sub = Get-AzureRmSubscription -SubscriptionId xxxx -TenantId yyyy
Set-AzureRmContext -SubscriptionObject $sub
# Alternatively, you can use piping
Get-AzureRmSubscription -SubscriptionId xxxx -TenantId yyyy | Set-AzureRmContext
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, this works:
PS C:\Users\markcowl> Get-AzureRmSubscription | Set-AzureRmContext
Name : [markcowl@microsoft.com, xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx]
Account : markcowl@microsoft.com
SubscriptionName : node
TenantId : xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx
Environment : AzureCloud
Name : [markcowl@microsoft.com, xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx]
Account : markcowl@microsoft.com
SubscriptionName : Azure SDK CI
TenantId : xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx
Environment : AzureCloud
Name : [markcowl@microsoft.com, xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx]
Account : markcowl@microsoft.com
SubscriptionName : Node CLI Test
TenantId : xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx
Environment : AzureCloud
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PowerShell is smart enough to accept pipeline input for a subscription or a context for this cmdlet
@azuresdkci add to whitelist |
@cormacpayne Thanks for the feedback! I think I have amended the PR correctly (my first time amending a PR on here) 😓 |
@SteGriff no worries at all! We appreciate the fix |
Description
Fixed the examples of returned fields in Get-AzureRmSubscription. Added an extra piped statement to Example 4 because it would not naturally work with the newly renamed fields.
Fixes issue #4935
This checklist is used to make sure that common guidelines for a pull request are followed. You can find a more complete discussion of PowerShell cmdlet best practices here.
General Guidelines
Testing Guidelines
Cmdlet Signature Guidelines
ShouldProcess
and haveSupportShouldProcess=true
specified in the cmdlet attribute. You can find more information onShouldProcess
here.OutputType
attribute if any output is produced - if the cmdlet produces no output, it should implement aPassThru
parameter.Cmdlet Parameter Guidelines