Azure / azure-powershell

Microsoft Azure PowerShell
Other
4.26k stars 3.86k forks source link

Connect-AzAccount adds an error to $error #13288

Closed fuglphoenix closed 4 years ago

fuglphoenix commented 4 years ago

Description

when using Connect-AzAccount in an Azure runbook i get an error. It is not thrown but it is located in $error variable

Steps to reproduce

Create an Azure runbook

$spc = Get-AutomationConnection -Name "AzureRunAsConnection" 
$error.clear()
$out = Connect-AzAccount -ServicePrincipal `
                -TenantId $spc.TenantId `
                -ApplicationId $spc.ApplicationId `
                -CertificateThumbprint $spc.CertificateThumbprint  
if ($error){
    Write-Output $($error -join [Environment]::NewLine)
}

Output:

Method invocation failed because [Microsoft.Azure.PowerShell.Authenticators.DesktopAuthenticatorBuilder] does not contain a method named 'Apply'.

Environment data

Name                           Value                                                                                    
----                           -----                                                                                    
PSVersion                      5.1.15063.726                                                                            
PSEdition                      Desktop                                                                                  
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                  
BuildVersion                   10.0.15063.726                                                                           
CLRVersion                     4.0.30319.42000                                                                          
WSManStackVersion              3.0                                                                                      
PSRemotingProtocolVersion      2.3                                                                                      
SerializationVersion           1.1.0.1       

Module versions

    Directory: C:\Modules\User
ModuleType Version    Name                                ExportedCommands                                              
---------- -------    ----                                ----------------                                              
Script     2.0.1      Az.Accounts                         {Disable-AzDataCollection, Disable-AzContextAutosave, Enabl...
Script     1.1.2      Az.AnalysisServices                 {Resume-AzAnalysisServicesServer, Suspend-AzAnalysisService...
Script     1.3.6      Az.Automation                       {Get-AzAutomationHybridWorkerGroup, Remove-AzAutomationHybr...
Script     2.0.2      Az.Batch                            {Remove-AzBatchAccount, Get-AzBatchAccount, Get-AzBatchAcco...
Script     1.4.2      Az.Cdn                              {Get-AzCdnProfile, Get-AzCdnProfileSsoUrl, New-AzCdnProfile...
Script     3.5.0      Az.Compute                          {Remove-AzAvailabilitySet, Get-AzAvailabilitySet, New-AzAva...
Script     1.1.1      Az.ContainerRegistry                {New-AzContainerRegistry, Get-AzContainerRegistry, Update-A...
Script     1.5.1      Az.KeyVault                         {Add-AzKeyVaultCertificate, Update-AzKeyVaultCertificate, S...
Script     1.6.1      Az.Monitor                          {Get-AzMetricDefinition, Get-AzMetric, Remove-AzLogProfile,...
Script     1.1.1      Az.PowerBIEmbedded                  {Remove-AzPowerBIWorkspaceCollection, Get-AzPowerBIWorkspac...
Script     1.12.0     Az.Resources                        {Get-AzProviderOperation, Remove-AzRoleAssignment, Get-AzRo...
Script     1.13.0     Az.Storage                          {Get-AzStorageAccount, Get-AzStorageAccountKey, New-AzStora...
Script     4.6.1      Azure.Storage                       {Get-AzureStorageTable, New-AzureStorageTableSASToken, New-...
Binary     2.0.2.76   AzureAD                             {Add-AzureADApplicationOwner, Get-AzureADApplication, Get-A...
Script     6.1.1      AzureRM.Automation                  {Get-AzureRMAutomationHybridWorkerGroup, Remove-AzureRmAuto...
Script     5.9.1      AzureRM.Compute                     {Remove-AzureRmAvailabilitySet, Get-AzureRmAvailabilitySet,...
Script     5.8.3      AzureRM.Profile                     {Disable-AzureRmDataCollection, Disable-AzureRmContextAutos...
Script     6.7.3      AzureRM.Resources                   {Get-AzureRmProviderOperation, Remove-AzureRmRoleAssignment...
Script     4.12.1     AzureRM.Sql                         {Get-AzureRmSqlDatabaseTransparentDataEncryption, Get-Azure...
Script     5.2.0      AzureRM.Storage                     {Get-AzureRmStorageAccount, Get-AzureRmStorageAccountKey, N...
Script     1.3        CasenumberHelper2                   {Get-Path, Get-CaseNumLetter, Get-ArchivePath, Get-CaseNume...
Script     1.0        EmailHandler                        Send-EmailNotification                                        
Script     1.0        PSTeams                             {New-TeamsActivityImage, New-TeamsActivitySubtitle, New-Tea...
Script     1.3        SJmessages                          {init, send-TmessageError, send-TmessageSQL, send-TmessageS...
Script     21.1.18135 SqlServer                           {Add-RoleMember, Add-SqlAvailabilityDatabase, Add-SqlAvaila...
Manifest   5.15.2.0   WinSCP                              {ConvertTo-WinSCPEscapedString, Copy-WinSCPItem, Get-WinSCP...
    Directory: C:\Modules\Global

ModuleType Version    Name                                ExportedCommands                                              
---------- -------    ----                                ----------------                                              
Manifest   1.1.0.0    AuditPolicyDsc                                                                                    
Manifest   5.0.0.0    ComputerManagementDsc                                                                             
Script     0.2        GPRegistryPolicyParser              {Parse-PolFile, Read-RegistryPolicies, Create-RegistrySetti...
Script     0.0        Microsoft.PowerShell.Core                                                                         
Script     0.0        Microsoft.PowerShell.Diagnostics                                                                  
Script     0.0        Microsoft.PowerShell.Management                                                                   
Script     0.0        Microsoft.PowerShell.Security                                                                     
Script     0.0        Microsoft.PowerShell.Utility                                                                      
Script     0.0        Microsoft.WSMan.Management                                                                        
Binary     1.0        Orchestrator.AssetManagement.Cmd... {Get-AutomationCertificate, Get-AutomationConnection, Get-S...
Manifest   2.9.0.0    PSDscResources                                                                                    
Manifest   2.1.0.0    SecurityPolicyDsc                                                                                 
Manifest   1.0        StateConfigCompositeResources                                                                     
Manifest   1.1        xDSCDomainjoin                                                                                    
Manifest   1.1.0.0    xPowerShellExecutionPolicy          {Get-TargetResource, Test-TargetResource, Set-TargetResource} 
Manifest   1.1.0.0    xRemoteDesktopAdmin                                                                               
    Directory: C:\Program Files\WindowsPowerShell\Modules

ModuleType Version    Name                                ExportedCommands                                              
---------- -------    ----                                ----------------                                              
Script     1.0.1      Microsoft.PowerShell.Operation.V... {Get-OperationValidation, Invoke-OperationValidation}         
Binary     1.0.0.1    PackageManagement                   {Find-Package, Get-Package, Get-PackageProvider, Get-Packag...
Script     3.4.0      Pester                              {Describe, Context, It, Should...}                            
Script     1.0.0.1    PowerShellGet                       {Install-Module, Find-Module, Save-Module, Update-Module...}  
Script     1.2        PSReadline                          {Get-PSReadlineKeyHandler, Set-PSReadlineKeyHandler, Remove...
    Directory: C:\Windows\system32\WindowsPowerShell\v1.0\Modules

ModuleType Version    Name                                ExportedCommands                                              
---------- -------    ----                                ----------------                                              
Manifest   1.0.0.0    AppBackgroundTask                   {Disable-AppBackgroundTaskDiagnosticLog, Enable-AppBackgrou...
Manifest   2.0.0.0    Appx                                {Add-AppxPackage, Get-AppxPackage, Get-AppxPackageManifest,...
Manifest   2.0.0.0    BitsTransfer                        {Add-BitsFile, Complete-BitsTransfer, Get-BitsTransfer, Rem...
Manifest   1.0.0.0    CimCmdlets                          {Get-CimAssociatedInstance, Get-CimClass, Get-CimInstance, ...
Manifest   1.0        Defender                            {Get-MpPreference, Set-MpPreference, Add-MpPreference, Remo...
Manifest   1.0.0.0    DeliveryOptimization                {Get-DeliveryOptimizationStatus, Get-DeliveryOptimizationPe...
Manifest   1.0.0.0    DirectAccessClientComponents        {Disable-DAManualEntryPointSelection, Enable-DAManualEntryP...
Script     3.0        Dism                                {Add-AppxProvisionedPackage, Add-WindowsDriver, Add-Windows...
Manifest   1.0.0.0    DnsClient                           {Resolve-DnsName, Clear-DnsClientCache, Get-DnsClient, Get-...
Manifest   1.0.0.0    EventTracingManagement              {Start-EtwTraceSession, New-EtwTraceSession, Get-EtwTraceSe...
Manifest   2.0.0.0    International                       {Get-WinDefaultInputMethodOverride, Set-WinDefaultInputMeth...
Manifest   1.0.0.0    iSCSI                               {Get-IscsiTargetPortal, New-IscsiTargetPortal, Remove-Iscsi...
Script     1.0.0.0    ISE                                 {New-IseSnippet, Import-IseSnippet, Get-IseSnippet}           
Manifest   1.0.0.0    Kds                                 {Add-KdsRootKey, Get-KdsRootKey, Test-KdsRootKey, Set-KdsCo...
Manifest   1.0.1.0    Microsoft.PowerShell.Archive        {Compress-Archive, Expand-Archive}                            
Manifest   3.0.0.0    Microsoft.PowerShell.Diagnostics    {Get-WinEvent, Get-Counter, Import-Counter, Export-Counter...}
Manifest   3.0.0.0    Microsoft.PowerShell.Host           {Start-Transcript, Stop-Transcript}                           
Manifest   1.0.0.0    Microsoft.PowerShell.LocalAccounts  {Add-LocalGroupMember, Disable-LocalUser, Enable-LocalUser,...
Manifest   3.1.0.0    Microsoft.PowerShell.Management     {Add-Content, Clear-Content, Clear-ItemProperty, Join-Path...}
Script     1.0        Microsoft.PowerShell.ODataUtils     Export-ODataEndpointProxy                                     
Manifest   3.0.0.0    Microsoft.PowerShell.Security       {Get-Acl, Set-Acl, Get-PfxCertificate, Get-Credential...}     
Manifest   3.1.0.0    Microsoft.PowerShell.Utility        {Format-List, Format-Custom, Format-Table, Format-Wide...}    
Manifest   3.0.0.0    Microsoft.WSMan.Management          {Disable-WSManCredSSP, Enable-WSManCredSSP, Get-WSManCredSS...
Manifest   1.0        MMAgent                             {Disable-MMAgent, Enable-MMAgent, Set-MMAgent, Get-MMAgent...}
Manifest   1.0.0.0    MsDtc                               {New-DtcDiagnosticTransaction, Complete-DtcDiagnosticTransa...
Manifest   2.0.0.0    NetAdapter                          {Disable-NetAdapter, Disable-NetAdapterBinding, Disable-Net...
Manifest   1.0.0.0    NetConnection                       {Get-NetConnectionProfile, Set-NetConnectionProfile}          
Manifest   1.0.0.0    NetEventPacketCapture               {New-NetEventSession, Remove-NetEventSession, Get-NetEventS...
Manifest   2.0.0.0    NetLbfo                             {Add-NetLbfoTeamMember, Add-NetLbfoTeamNic, Get-NetLbfoTeam...
Manifest   1.0.0.0    NetNat                              {Get-NetNat, Get-NetNatExternalAddress, Get-NetNatStaticMap...
Manifest   2.0.0.0    NetQos                              {Get-NetQosPolicy, Set-NetQosPolicy, Remove-NetQosPolicy, N...
Manifest   2.0.0.0    NetSecurity                         {Get-DAPolicyChange, New-NetIPsecAuthProposal, New-NetIPsec...
Manifest   1.0.0.0    NetSwitchTeam                       {New-NetSwitchTeam, Remove-NetSwitchTeam, Get-NetSwitchTeam...
Manifest   1.0.0.0    NetTCPIP                            {Get-NetIPAddress, Get-NetIPInterface, Get-NetIPv4Protocol,...
Manifest   1.0.0.0    NetworkConnectivityStatus           {Get-DAConnectionStatus, Get-NCSIPolicyConfiguration, Reset...
Manifest   1.0.0.0    NetworkSwitchManager                {Disable-NetworkSwitchEthernetPort, Enable-NetworkSwitchEth...
Manifest   1.0.0.0    NetworkTransition                   {Add-NetIPHttpsCertBinding, Disable-NetDnsTransitionConfigu...
Manifest   1.0.0.0    PcsvDevice                          {Get-PcsvDevice, Start-PcsvDevice, Stop-PcsvDevice, Restart...
Manifest   1.0.0.0    PKI                                 {Add-CertificateEnrollmentPolicyServer, Export-Certificate,...
Manifest   1.0.0.0    PnpDevice                           {Get-PnpDevice, Get-PnpDeviceProperty, Enable-PnpDevice, Di...
Manifest   1.1        PrintManagement                     {Add-Printer, Add-PrinterDriver, Add-PrinterPort, Get-Print...
Script     3.0        Provisioning                        {Install-ProvisioningPackage, Export-ProvisioningPackage, I...
Manifest   1.1        PSDesiredStateConfiguration         {Set-DscLocalConfigurationManager, Start-DscConfiguration, ...
Script     1.0.0.0    PSDiagnostics                       {Disable-PSTrace, Disable-PSWSManCombinedTrace, Disable-WSM...
Binary     1.1.0.0    PSScheduledJob                      {New-JobTrigger, Add-JobTrigger, Remove-JobTrigger, Get-Job...
Manifest   2.0.0.0    PSWorkflow                          {New-PSWorkflowExecutionOption, New-PSWorkflowSession, nwsn}  
Manifest   1.0.0.0    PSWorkflowUtility                   Invoke-AsWorkflow                                             
Manifest   1.0.0.0    ScheduledTasks                      {Get-ScheduledTask, Set-ScheduledTask, Register-ScheduledTa...
Manifest   2.0.0.0    SecureBoot                          {Confirm-SecureBootUEFI, Set-SecureBootUEFI, Get-SecureBoot...
Manifest   2.0.0.0    SmbShare                            {Get-SmbShare, Remove-SmbShare, Set-SmbShare, Block-SmbShar...
Manifest   2.0.0.0    SmbWitness                          {Get-SmbWitnessClient, Move-SmbWitnessClient, gsmbw, msmbw...}
Manifest   1.0.0.0    StartLayout                         {Export-StartLayout, Import-StartLayout, Export-StartLayout...
Manifest   2.0.0.0    Storage                             {Add-InitiatorIdToMaskingSet, Add-PartitionAccessPath, Add-...
Manifest   2.0.0.0    TLS                                 {New-TlsSessionTicketKey, Enable-TlsSessionTicketKey, Disab...
Manifest   1.0.0.0    TroubleshootingPack                 {Get-TroubleshootingPack, Invoke-TroubleshootingPack}         
Manifest   2.0.0.0    TrustedPlatformModule               {Get-Tpm, Initialize-Tpm, Clear-Tpm, Unblock-Tpm...}          
Manifest   2.0.0.0    VpnClient                           {Add-VpnConnection, Set-VpnConnection, Remove-VpnConnection...
Manifest   1.0.0.0    Wdac                                {Get-OdbcDriver, Set-OdbcDriver, Get-OdbcDsn, Add-OdbcDsn...} 
Manifest   1.0.0.0    WindowsDeveloperLicense             {Get-WindowsDeveloperLicense, Unregister-WindowsDeveloperLi...
Script     1.0        WindowsErrorReporting               {Enable-WindowsErrorReporting, Disable-WindowsErrorReportin...
Manifest   1.0.0.0    WindowsSearch                       {Get-WindowsSearchSetting, Set-WindowsSearchSetting}          
Manifest   1.0.0.0    WindowsUpdate                       Get-WindowsUpdateLog

Debug output

no output

Error output

InnerException   : False
Exception        : System.Management.Automation.RuntimeException: Method invocation failed because 
                   [Microsoft.Azure.PowerShell.Authenticators.DesktopAuthenticatorBuilder] does not contain a method 
                   named 'Apply'.
                      at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext 
                   funcContext, Exception exception)
                      at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
                      at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame 
                   frame)
                      at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame 
                   frame)
Message          : Method invocation failed because 
                   [Microsoft.Azure.PowerShell.Authenticators.DesktopAuthenticatorBuilder] does not contain a method 
                   named 'Apply'.
StackTrace       :    at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext 
                   funcContext, Exception exception)
                      at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
                      at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame 
                   frame)
                      at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame 
                   frame)
HelpLink         : 
ErrorDetails     : 
ErrorCategory    : InvalidOperation: (:) [], RuntimeException
InvocationInfo   : System.Management.Automation.InvocationInfo
ScriptStackTrace : at <ScriptBlock>, C:\Modules\User\Az.Accounts\PostImportScripts\LoadAuthenticators.ps1: line 3
                   at <ScriptBlock>, C:\Modules\User\Az.Accounts\Az.Accounts.psm1: line 89
                   at <ScriptBlock>, C:\Modules\User\Az.Accounts\Az.Accounts.psm1: line 88
                   at <ScriptBlock>, <No file>: line 4
dingmeng-xue commented 4 years ago

@fuglphoenix , thanks for reporting. the message written into $error is a false alarm, because it is PowerShell mechanism and any error will be written into it but it is not a real problem from Azure PowerShell.

We believe we have fixed this problem in upcoming release. Please verify it again after new Az.Accounts 2.x available in the next week.

dingmeng-xue commented 4 years ago

I tried Az.Accounts 2.1.0 and cannot reproduce the issue. Please confirm as well.

fuglphoenix commented 4 years ago

@dingmeng-xue I can comfirm that it is now working

dingmeng-xue commented 4 years ago

Thanks for confirmation. Please contact us if you have further question.