VincentZHANG
VincentZHANG

Reputation: 787

How to Provide a Value in PowerShell CLI Prompt for a Parameter of Complex Type

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'

enter image description here

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

Answers (1)

Damien Caro
Damien Caro

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

Related Questions