'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'
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!
Solution 1:[1]
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://docs.microsoft.com/en-us/powershell/azure/context-persistence
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Damien Caro |

