Skip to content

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

Merged
merged 2 commits into from
Nov 15, 2017

Conversation

SteGriff
Copy link
Contributor

@SteGriff SteGriff commented Nov 8, 2017

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

  • Title of the pull request is clear and informative.
  • There are a small number of commits, each of which have an informative message. This means that previously merged commits do not appear in the history of the PR. For more information on cleaning up the commits in your PR, see this page.
  • The pull request does not introduce breaking changes (unless a major version change occurs in the assembly and module).

Testing Guidelines

  • Pull request includes test coverage for the included changes.
  • PowerShell scripts used in tests should do any necessary setup as part of the test or suite setup, and should not use hard-coded values for locations or existing resources.

Cmdlet Signature Guidelines

  • New cmdlets that make changes or have side effects should implement ShouldProcess and have SupportShouldProcess=true specified in the cmdlet attribute. You can find more information on ShouldProcess here.
  • Cmdlet specifies OutputType attribute if any output is produced - if the cmdlet produces no output, it should implement a PassThru parameter.

Cmdlet Parameter Guidelines

  • Parameter types should not expose types from the management library - complex parameter types should be defined in the module.
  • Complex parameter types are discouraged - a parameter type should be simple types as often as possible. If complex types are used, they should be shallow and easily creatable from a constructor or another cmdlet.
  • Cmdlet parameter sets should be mutually exclusive - each parameter set must have at least one mandatory parameter not in other parameter sets.

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.
@msftclas
Copy link

msftclas commented Nov 8, 2017

CLA assistant check
All CLA requirements met.

@azuresdkci
Copy link

Can one of the admins verify this patch?

@SteGriff
Copy link
Contributor Author

SteGriff commented Nov 8, 2017

Hi @cormacpayne, how does this look?

Copy link
Member

@cormacpayne cormacpayne left a 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 ☺️ I just had one minor comment that needed clarification

```

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
Copy link
Member

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 ☺️ )

Copy link
Contributor Author

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?

Copy link
Member

@cormacpayne cormacpayne Nov 9, 2017

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

Copy link
Member

@markcowl markcowl Nov 11, 2017

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

Copy link
Member

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

@cormacpayne
Copy link
Member

@azuresdkci add to whitelist

@SteGriff
Copy link
Contributor Author

@cormacpayne Thanks for the feedback! I think I have amended the PR correctly (my first time amending a PR on here) 😓

@cormacpayne
Copy link
Member

@SteGriff no worries at all! We appreciate the fix ☺️ The changes in this PR look good to me, so I'll go ahead and merge it later today or tomorrow when we are finished with a release we're doing (need to make sure the release branch gets merged back into preview before merging anything into preview).

@markcowl markcowl merged commit 1352d2a into Azure:preview Nov 15, 2017
@SteGriff SteGriff deleted the patch-1 branch November 15, 2017 08:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants