Reputation: 787
Here is a perfect example to explain my question. I am running the following Azure PowerShell cmdlet:
Set-AzContext -Name 'MY-CONTEXT-NAME'
And it turns out that I have to provide the value for the -Context parameter as well to make it work. So, it prompts me to provide a value for it.
Context is of type Microsoft.Azure.Commands.Profile.Models.Core.PSAzureContext, and according to the document, command Get-AzContext returns an object of that type. So, I typed the following script right after the input prompt for Context:
Get-AzContext -Name 'MY-CONTEXT-NAME'
As you can see from the screenshot, the whole command is taken as a string value to be passed for Context. Is there a way to let it know that I want to execute the string as a command and use its execution result as the value for the Context parameter?
Many Thanks!
Upvotes: 1
Views: 420
Reputation: 70
You should be considering piping those cmdlets like this:
Get-AzContext 'My-Context-Name' | Set-AzContext
More details in the "Azure PowerShell context objects" https://learn.microsoft.com/en-us/powershell/azure/context-persistence
Upvotes: 1