azure-powershell
azure-powershell copied to clipboard
The '-DefaultProfile' parameter are not supported by some cmdlets but are presented
Description
Cmdlets are generated by autorest.powershell provides the parameter -DefaultProfile
, which actually are not functional actually.
And below are some workarounds.
- You use may
set-azcontext
to switch the context instead of using-DefaultProfile
. - If you just need to specify the subscription. you may use the
-SubscriptionId
parameters, which are supported by those autogen cmdlets.
Steps that will be taken considering removing those un-functional -DefaultProfile
are breaking changes even if they are not functional
- Add a warning message when
-DefaultProfile
is used to tell users the parameter is not functional and will be removed - Remove those
-DefaultProfile
- Add them back if
-DefaultProfile
is supported by the generator autorest.powershell.
Link to the feature request in autorest.powershell.
Issue script & Debug output
None
Environment data
None
Module versions
The bug happens in all generated cmdlets.
Error output
None
Removing -DefaultProfile should not be the solution. Of the 2 workarounds offered:
- Set-AzContext is not thread safe. If you run Az cmdlets in multi-threaded environments (Azure Functions or Powershell runspaces) then you cannot use Set-AzContext
- Using -SubscriptionId parameter doesn't help with tenants. -DefaultProfile allows passing in contexts associated with different tenants.
Multi-subscription and multi-tenant management at scale is becoming more common among the largest Azure customers, and removing -DefaultProfile will effectively eliminate Az cmdlets as a potential option in these types of infrastructures.
I agree with @kwill-MSFT , removing the "defaultProfile" or AzContext as a parameter is NOT a solution. We run our code in azure functions, and we need to be able to pass the right context as a parameter for functions that fan-out and do work. With recent changes to the Azure Policy and the use of autorest , our code broke, not because of the new "output" from some cmdlets which was expected/announced but rather because some cmdlets like Get-AzPolicyAssignment no longer support the DefaultProfile/AzContext parameter (it's useless/ignored).
In the past, where we ran into issues with set-azcontext for multi-tenant environments and azure functions, Microsoft explicitly asked us to always pass the context to each az cmdlet , so please take into consideration this and bring this back as this is the only reliable way of handling multi-tenant environments where is imperative we ensure we perform the action with the right context when running code in azure functions.