Azure / azure-powershell

Microsoft Azure PowerShell
Other
4.22k stars 3.83k forks source link

Connect-AzAccount Throws Object reference not set to an instance of an object #9467

Open rafaci opened 5 years ago

rafaci commented 5 years ago

Description

I'm writing an application that needs to pull a secret from Azure Key Vault in PowerShell. This application will run on Azure Batch. I'm able to call Connect-AzAccount successfully from my dev box, but when I try running it on an Azure VM in Azure Batch, it fails. I'm using certificate authentication and the certificate is exists in both places (I get a different error message if I provide an invalid certificate thumbprint.) I'm not sure what else could be different between the environments

Steps to reproduce

Connect-AzAccount -ServicePrincipal -TenantId $tenantId -CertificateThumbprint $thumbprint -ApplicationId $appId

Environment data

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

Module versions

PS C:\windows\system32> Get-Module -ListAvailable

    Directory: C:\Program Files\WindowsPowerShell\Modules

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     2.0.0      Az.Accounts                         {Disable-AzDataCollection, Disable-AzContextAutosave, Enab...
Script     1.0.1      Az.Aks                              {Get-AzAks, New-AzAks, Remove-AzAks, Import-AzAksCredentia...
Script     1.1.0      Az.AnalysisServices                 {Resume-AzAnalysisServicesServer, Suspend-AzAnalysisServic...
Script     1.1.0      Az.ApiManagement                    {Add-AzApiManagementApiToProduct, Add-AzApiManagementProdu...
Script     1.0.0      Az.ApplicationInsights              {Get-AzApplicationInsights, New-AzApplicationInsights, Rem...
Script     1.2.2      Az.Automation                       {Get-AzAutomationHybridWorkerGroup, Remove-AzAutomationHyb...
Script     1.1.0      Az.Batch                            {Remove-AzBatchAccount, Get-AzBatchAccount, Get-AzBatchAcc...
Script     1.0.0      Az.Billing                          {Get-AzBillingInvoice, Get-AzBillingPeriod, Get-AzEnrollme...
Script     1.3.0      Az.Cdn                              {Get-AzCdnProfile, Get-AzCdnProfileSsoUrl, New-AzCdnProfil...
Script     1.1.1      Az.CognitiveServices                {Get-AzCognitiveServicesAccount, Get-AzCognitiveServicesAc...
Script     2.3.0      Az.Compute                          {Remove-AzAvailabilitySet, Get-AzAvailabilitySet, New-AzAv...
Script     1.0.1      Az.ContainerInstance                {New-AzContainerGroup, Get-AzContainerGroup, Remove-AzCont...
Script     1.0.1      Az.ContainerRegistry                {New-AzContainerRegistry, Get-AzContainerRegistry, Update-...
Script     1.1.1      Az.DataFactory                      {Set-AzDataFactoryV2, Update-AzDataFactoryV2, Get-AzDataFa...
Script     1.0.0      Az.DataLakeAnalytics                {Get-AzDataLakeAnalyticsDataSource, New-AzDataLakeAnalytic...
Script     1.2.1      Az.DataLakeStore                    {Get-AzDataLakeStoreTrustedIdProvider, Remove-AzDataLakeSt...
Script     1.0.0      Az.DeploymentManager                {Get-AzDeploymentManagerArtifactSource, New-AzDeploymentMa...
Script     1.0.0      Az.DevTestLabs                      {Get-AzDtlAllowedVMSizesPolicy, Get-AzDtlAutoShutdownPolic...
Script     1.1.1      Az.Dns                              {Get-AzDnsRecordSet, New-AzDnsRecordConfig, Remove-AzDnsRe...
Script     1.2.0      Az.EventGrid                        {New-AzEventGridTopic, Get-AzEventGridTopic, Set-AzEventGr...
Script     1.2.0      Az.EventHub                         {New-AzEventHubNamespace, Get-AzEventHubNamespace, Set-AzE...
Script     1.1.0      Az.FrontDoor                        {New-AzFrontDoor, Get-AzFrontDoor, Set-AzFrontDoor, Remove...
Script     2.0.0      Az.HDInsight                        {Get-AzHDInsightJob, New-AzHDInsightSqoopJobDefinition, Wa...
Script     1.1.0      Az.IotHub                           {Add-AzIotHubKey, Get-AzIotHubEventHubConsumerGroup, Get-A...
Script     1.2.0      Az.KeyVault                         {Add-AzKeyVaultCertificate, Update-AzKeyVaultCertificate, ...
Script     1.2.1      Az.LogicApp                         {Get-AzIntegrationAccountAgreement, Get-AzIntegrationAccou...
Script     1.1.0      Az.MachineLearning                  {Move-AzMlCommitmentAssociation, Get-AzMlCommitmentAssocia...
Script     1.0.0      Az.MarketplaceOrdering              {Get-AzMarketplaceTerms, Set-AzMarketplaceTerms}
Script     1.1.0      Az.Media                            {Sync-AzMediaServiceStorageKey, Set-AzMediaServiceKey, Get...
Script     1.2.1      Az.Monitor                          {Get-AzMetricDefinition, Get-AzMetric, Remove-AzLogProfile...
Script     1.10.0     Az.Network                          {Add-AzApplicationGatewayAuthenticationCertificate, Get-Az...
Script     1.1.0      Az.NotificationHubs                 {Get-AzNotificationHub, Get-AzNotificationHubAuthorization...
Script     1.3.0      Az.OperationalInsights              {New-AzOperationalInsightsAzureActivityLogDataSource, New-...
Script     1.1.1      Az.PolicyInsights                   {Get-AzPolicyEvent, Get-AzPolicyState, Get-AzPolicyStateSu...
Script     1.1.0      Az.PowerBIEmbedded                  {Remove-AzPowerBIWorkspaceCollection, Get-AzPowerBIWorkspa...
Script     1.4.1      Az.RecoveryServices                 {Get-AzRecoveryServicesBackupProperty, Get-AzRecoveryServi...
Script     1.1.0      Az.RedisCache                       {Remove-AzRedisCachePatchSchedule, New-AzRedisCacheSchedul...
Script     1.0.1      Az.Relay                            {New-AzRelayNamespace, Get-AzRelayNamespace, Set-AzRelayNa...
Script     1.5.0      Az.Resources                        {Get-AzProviderOperation, Remove-AzRoleAssignment, Get-AzR...
Script     1.2.0      Az.ServiceBus                       {New-AzServiceBusNamespace, Get-AzServiceBusNamespace, Set...
Script     1.1.1      Az.ServiceFabric                    {Add-AzServiceFabricApplicationCertificate, Add-AzServiceF...
Script     1.0.2      Az.SignalR                          {New-AzSignalR, Get-AzSignalR, Get-AzSignalRKey, New-AzSig...
Script     1.12.0     Az.Sql                              {Get-AzSqlDatabaseTransparentDataEncryption, Get-AzSqlData...
Script     1.4.0      Az.Storage                          {Get-AzStorageAccount, Get-AzStorageAccountKey, New-AzStor...
Script     1.0.0      Az.StreamAnalytics                  {Get-AzStreamAnalyticsFunction, Get-AzStreamAnalyticsDefau...
Script     1.0.1      Az.TrafficManager                   {Add-AzTrafficManagerCustomHeaderToEndpoint, Remove-AzTraf...
Script     1.3.0      Az.Websites                         {Get-AzAppServicePlan, Set-AzAppServicePlan, New-AzAppServ...
Script     1.0.1      Microsoft.PowerShell.Operation.V... {Get-OperationValidation, Invoke-OperationValidation}
Script     1.4.2      PackageManagement                   {Find-Package, Get-Package, Get-PackageProvider, Get-Packa...
Binary     1.0.0.1    PackageManagement                   {Find-Package, Get-Package, Get-PackageProvider, Get-Packa...
Script     3.4.0      Pester                              {Describe, Context, It, Should...}
Script     2.1.5      PowerShellGet                       {Find-Command, Find-DSCResource, Find-Module, Find-RoleCap...
Script     1.0.0.1    PowerShellGet                       {Install-Module, Find-Module, Save-Module, Update-Module...}
Script     2.0.0      PSReadline                          {Get-PSReadLineKeyHandler, Set-PSReadLineKeyHandler, Remov...

    Directory: C:\windows\system32\WindowsPowerShell\v1.0\Modules

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Manifest   1.0.0.0    AppBackgroundTask                   {Disable-AppBackgroundTaskDiagnosticLog, Enable-AppBackgro...
Manifest   2.0.0.0    AppLocker                           {Get-AppLockerFileInformation, Get-AppLockerPolicy, New-Ap...
Manifest   1.0.0.0    AppvClient                          {Add-AppvClientConnectionGroup, Add-AppvClientPackage, Add...
Manifest   2.0.1.0    Appx                                {Add-AppxPackage, Get-AppxPackage, Get-AppxPackageManifest...
Manifest   1.0        BestPractices                       {Get-BpaModel, Get-BpaResult, Invoke-BpaModel, Set-BpaResult}
Manifest   1.0.0.0    BitLocker                           {Unlock-BitLocker, Suspend-BitLocker, Resume-BitLocker, Re...
Manifest   2.0.0.0    BitsTransfer                        {Add-BitsFile, Complete-BitsTransfer, Get-BitsTransfer, Re...
Manifest   1.0.0.0    BranchCache                         {Add-BCDataCacheExtension, Clear-BCCache, Disable-BC, Disa...
Manifest   1.0.0.0    CimCmdlets                          {Get-CimAssociatedInstance, Get-CimClass, Get-CimInstance,...
Manifest   1.0        ConfigCI                            {Get-SystemDriver, New-CIPolicyRule, New-CIPolicy, Get-CIP...
Manifest   1.0        Defender                            {Get-MpPreference, Set-MpPreference, Add-MpPreference, Rem...
Manifest   1.0.1.0    DeliveryOptimization                {Get-DeliveryOptimizationStatus, Get-DeliveryOptimizationP...
Binary     2.0.0.0    DFSR                                {New-DfsReplicationGroup, Get-DfsReplicationGroup, Set-Dfs...
Manifest   1.0.0.0    DirectAccessClientComponents        {Disable-DAManualEntryPointSelection, Enable-DAManualEntry...
Script     3.0        Dism                                {Add-AppxProvisionedPackage, Add-WindowsDriver, Add-Window...
Manifest   1.0.0.0    DnsClient                           {Resolve-DnsName, Clear-DnsClientCache, Get-DnsClient, Get...
Manifest   1.0.0.0    EventTracingManagement              {Start-EtwTraceSession, New-EtwTraceSession, Get-EtwTraceS...
Manifest   2.0.0.0    International                       {Get-WinDefaultInputMethodOverride, Set-WinDefaultInputMet...
Manifest   1.0.0.0    iSCSI                               {Get-IscsiTargetPortal, New-IscsiTargetPortal, Remove-Iscs...
Manifest   2.0.0.0    IscsiTarget                         {Add-ClusteriSCSITargetServerRole, Add-IscsiVirtualDiskTar...
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-KdsC...
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-WSManCredS...
Manifest   1.0        MMAgent                             {Disable-MMAgent, Enable-MMAgent, Set-MMAgent, Get-MMAgent...
Manifest   1.0.0.0    MsDtc                               {New-DtcDiagnosticTransaction, Complete-DtcDiagnosticTrans...
Manifest   2.0.0.0    NetAdapter                          {Disable-NetAdapter, Disable-NetAdapterBinding, Disable-Ne...
Manifest   1.0.0.0    NetConnection                       {Get-NetConnectionProfile, Set-NetConnectionProfile}
Manifest   1.0.0.0    NetDiagnostics                      Get-NetView
Manifest   1.0.0.0    NetEventPacketCapture               {New-NetEventSession, Remove-NetEventSession, Get-NetEvent...
Manifest   2.0.0.0    NetLbfo                             {Add-NetLbfoTeamMember, Add-NetLbfoTeamNic, Get-NetLbfoTea...
Manifest   1.0.0.0    NetNat                              {Get-NetNat, Get-NetNatExternalAddress, Get-NetNatStaticMa...
Manifest   2.0.0.0    NetQos                              {Get-NetQosPolicy, Set-NetQosPolicy, Remove-NetQosPolicy, ...
Manifest   2.0.0.0    NetSecurity                         {Get-DAPolicyChange, New-NetIPsecAuthProposal, New-NetIPse...
Manifest   1.0.0.0    NetSwitchTeam                       {New-NetSwitchTeam, Remove-NetSwitchTeam, Get-NetSwitchTea...
Manifest   1.0.0.0    NetTCPIP                            {Get-NetIPAddress, Get-NetIPInterface, Get-NetIPv4Protocol...
Manifest   1.0.0.0    NetworkConnectivityStatus           {Get-DAConnectionStatus, Get-NCSIPolicyConfiguration, Rese...
Manifest   1.0.0.0    NetworkSwitchManager                {Disable-NetworkSwitchEthernetPort, Enable-NetworkSwitchEt...
Manifest   1.0.0.0    NetworkTransition                   {Add-NetIPHttpsCertBinding, Disable-NetDnsTransitionConfig...
Manifest   1.0        NFS                                 {Get-NfsMappedIdentity, Get-NfsNetgroup, Install-NfsMappin...
Manifest   1.0.0.0    PcsvDevice                          {Get-PcsvDevice, Start-PcsvDevice, Stop-PcsvDevice, Restar...
Binary     1.0.0.0    PersistentMemory                    {Get-PmemDisk, Get-PmemPhysicalDevice, Get-PmemUnusedRegio...
Manifest   1.0.0.0    PKI                                 {Add-CertificateEnrollmentPolicyServer, Export-Certificate...
Manifest   1.0.0.0    PlatformIdentifier                  Get-PlatformIdentifier
Manifest   1.0.0.0    PnpDevice                           {Get-PnpDevice, Get-PnpDeviceProperty, Enable-PnpDevice, D...
Manifest   1.1        PrintManagement                     {Add-Printer, Add-PrinterDriver, Add-PrinterPort, Get-Prin...
Binary     1.0.11     ProcessMitigations                  {Get-ProcessMitigation, Set-ProcessMitigation, ConvertTo-P...
Manifest   1.1        PSDesiredStateConfiguration         {Set-DscLocalConfigurationManager, Start-DscConfiguration,...
Script     1.0.0.0    PSDiagnostics                       {Disable-PSTrace, Disable-PSWSManCombinedTrace, Disable-WS...
Binary     1.1.0.0    PSScheduledJob                      {New-JobTrigger, Add-JobTrigger, Remove-JobTrigger, Get-Jo...
Manifest   2.0.0.0    PSWorkflow                          {New-PSWorkflowExecutionOption, New-PSWorkflowSession, nwsn}
Manifest   1.0.0.0    PSWorkflowUtility                   Invoke-AsWorkflow
Manifest   2.0.0.0    RemoteDesktop                       {Get-RDCertificate, Set-RDCertificate, New-RDCertificate, ...
Manifest   1.0.0.0    ScheduledTasks                      {Get-ScheduledTask, Set-ScheduledTask, Register-ScheduledT...
Manifest   2.0.0.0    SecureBoot                          {Confirm-SecureBootUEFI, Set-SecureBootUEFI, Get-SecureBoo...
Manifest   1.0.0.0    SecurityCmdlets                     {Backup-SecurityPolicy, Restore-SecurityPolicy, Backup-Aud...
Script     1.0.0.0    ServerCore                          {Get-DisplayResolution, Set-DisplayResolution}
Script     2.0.0.0    ServerManager                       {Get-WindowsFeature, Install-WindowsFeature, Uninstall-Win...
Cim        1.0.0.0    ServerManagerTasks                  {Get-SMCounterSample, Get-SMPerformanceCollector, Start-SM...
Manifest   2.0.0.0    SmbShare                            {Get-SmbShare, Remove-SmbShare, Set-SmbShare, Block-SmbSha...
Manifest   2.0.0.0    SmbWitness                          {Get-SmbWitnessClient, Move-SmbWitnessClient, gsmbw, msmbw...
Manifest   2.0.0.0    SoftwareInventoryLogging            {Get-SilComputer, Get-SilComputerIdentity, Get-SilSoftware...
Manifest   1.0.0.0    StartLayout                         {Export-StartLayout, Import-StartLayout, Export-StartLayou...
Manifest   2.0.0.0    Storage                             {Add-InitiatorIdToMaskingSet, Add-PartitionAccessPath, Add...
Manifest   1.0.0.0    StorageBusCache                     {Clear-StorageBusDisk, Disable-StorageBusCache, Disable-St...
Manifest   2.0.0.0    TLS                                 {New-TlsSessionTicketKey, Enable-TlsSessionTicketKey, Disa...
Manifest   1.0.0.0    TroubleshootingPack                 {Get-TroubleshootingPack, Invoke-TroubleshootingPack}
Manifest   2.0.0.0    TrustedPlatformModule               {Get-Tpm, Initialize-Tpm, Clear-Tpm, Unblock-Tpm...}
Binary     2.1.639.0  UEV                                 {Clear-UevConfiguration, Clear-UevAppxPackage, Restore-Uev...
Manifest   1.0.0.0    UserAccessLogging                   {Enable-Ual, Disable-Ual, Get-Ual, Get-UalDns...}
Manifest   2.0.0.0    VpnClient                           {Add-VpnConnection, Set-VpnConnection, Remove-VpnConnectio...
Manifest   1.0.0.0    Wdac                                {Get-OdbcDriver, Set-OdbcDriver, Get-OdbcDsn, Add-OdbcDsn...}
Manifest   2.0.0.0    Whea                                {Get-WheaMemoryPolicy, Set-WheaMemoryPolicy}
Manifest   1.0.0.0    WindowsDeveloperLicense             {Get-WindowsDeveloperLicense, Unregister-WindowsDeveloperL...
Script     1.0        WindowsErrorReporting               {Enable-WindowsErrorReporting, Disable-WindowsErrorReporti...
Manifest   1.0.0.0    WindowsSearch                       {Get-WindowsSearchSetting, Set-WindowsSearchSetting}
Manifest   1.0.0.0    WindowsUpdate                       Get-WindowsUpdateLog
Manifest   1.0.0.2    WindowsUpdateProvider               {Get-WUAVersion, Get-WULastInstallationDate, Get-WULastSca...

Debug output

PS C:\windows\system32> Connect-AzAccount -ServicePrincipal -TenantId '72f988bf-86f1-41af-91ab-2d7cd011db47' -CertificateThumbprint $thumbprint -ApplicationId $appId
DEBUG: 4:48:52 PM - Autosave setting from startup session: 'CurrentUser'
DEBUG: 4:48:52 PM - No autosave setting detected in environment variable 'AzContextAutoSave'.
DEBUG: 4:48:52 PM - Using Autosave scope 'CurrentUser'
Connect-AzAccount : Object reference not set to an instance of an object.
At line:1 char:1
+ Connect-AzAccount -ServicePrincipal -TenantId '72f988bf-86f1-41af-91a ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [Connect-AzAccount], NullReferenceException
    + FullyQualifiedErrorId : Microsoft.Azure.Commands.Profile.ConnectAzureRmAccountCommand

DEBUG: 4:48:54 PM - ConnectAzureRmAccountCommand end processing.
DEBUG: 4:48:54 PM - ConnectAzureRmAccountCommand end processing.

Error output

   HistoryId: 12

Message        : Object reference not set to an instance of an object.
StackTrace     :    at Microsoft.Azure.PowerShell.Authenticators.AuthenticationResultToken.get_UserId()
                    at Microsoft.Azure.Commands.Common.Authentication.Factories.AuthenticationFactory.Authenticate(IAzu
                 reAccount account, IAzureEnvironment environment, String tenant, SecureString password, String
                 promptBehavior, Action`1 promptAction, IAzureTokenCache tokenCache, String resourceId)
                    at Microsoft.Azure.Commands.Common.Authentication.Factories.AuthenticationFactory.Authenticate(IAzu
                 reAccount account, IAzureEnvironment environment, String tenant, SecureString password, String
                 promptBehavior, Action`1 promptAction, String resourceId)
                    at
                 Microsoft.Azure.Commands.ResourceManager.Common.RMProfileClient.AcquireAccessToken(IAzureAccount
                 account, IAzureEnvironment environment, String tenantId, SecureString password, String
                 promptBehavior, Action`1 promptAction)
                    at Microsoft.Azure.Commands.ResourceManager.Common.RMProfileClient.Login(IAzureAccount account,
                 IAzureEnvironment environment, String tenantId, String subscriptionId, String subscriptionName,
                 SecureString password, Boolean skipValidation, Action`1 promptAction, String name, Nullable`1
                 shouldPopulateContextList)
                    at Microsoft.Azure.Commands.Profile.ConnectAzureRmAccountCommand.<>c__DisplayClass92_0.<ExecuteCmdl
                 et>b__0(AzureRmProfile localProfile, RMProfileClient profileClient, String name)
                    at Microsoft.Azure.Commands.Profile.Common.AzureContextModificationCmdlet.ModifyContext(Action`2
                 contextAction)
                    at
                 Microsoft.Azure.Commands.Profile.ConnectAzureRmAccountCommand.SetContextWithOverwritePrompt(Action`3
                 setContextAction)
                    at Microsoft.Azure.Commands.Profile.ConnectAzureRmAccountCommand.ExecuteCmdlet()
                    at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord()
Exception      : System.NullReferenceException
InvocationInfo : {Connect-AzAccount}
Line           : Connect-AzAccount -ServicePrincipal -TenantId '72f988bf-86f1-41af-91ab-2d7cd011db47'
                 -CertificateThumbprint $thumbprint -ApplicationId $appId
Position       : At line:1 char:1
                 + Connect-AzAccount -ServicePrincipal -TenantId '72f988bf-86f1-41af-91a ...
                 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId      : 12
cormacpayne commented 5 years ago

@rafaci Hey Radwan, it looks like you're using the preview version of the Az.Accounts module that we released a couple months ago to test single sign-on support in Azure PowerShell. I would recommend only using this module to test this functionality with user accounts rather than service principals. Is there a reason that you are using this version of Az.Accounts rather than the stable version of this module and using service principal authentication with that? Regardless, this is a bug that we'll need to fix before merging it back into the stable version in a future release 😁

rafaci commented 5 years ago

Ah I see. I don't think I'm intentionally trying to install the preview version :) Should I be running a different command than the one below to get the latest stable version?

PS D:\Users\batch-explorer-user\Desktop> Install-Module -Name Az -AllowClobber
PackageManagement\Install-Package : Cannot convert value "2.0.0-preview" to type "System.Version". Error: "Input
string was not in a correct format."
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:1809 char:21
+ ...          $null = PackageManagement\Install-Package @PSBoundParameters
+                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (Microsoft.Power....InstallPackage:InstallPackage) [Install-Package], E
   xception
    + FullyQualifiedErrorId : InvalidCastParseTargetInvocation,New-PSGetItemInfo,Microsoft.PowerShell.PackageManagemen
   t.Cmdlets.InstallPackage
cormacpayne commented 5 years ago

@rafaci you will need the latest version of the PowerShellGet module (or at least version 1.6.0) to use the prerelease functionality for modules (even if you aren't looking to install prerelease modules 😁). To get the latest version, you can run the following command:

Install-Module -Name PowerShellGet -Repository PSGallery -Force
rafaci commented 5 years ago

Oh I see what was going on. Even though I had the latest version of PowerShellGet installed, it was running side by side with the old version. I had to delete C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1 to get Install-Module Az to work. Now it looks like I have 1.5.3 installed. Thanks for the help! :)

sqlsolver commented 5 years ago

@cormacpayne I am stuck on the same issue. My az.accounts version is 1.6, PowerShellGet is 2.1.3 and I'm on PowerShell 6.2.1. I am able to create the Service Principal using the same certificate, but not connect. The application ID was generated automatically when I created the Service Principal. Have tried Clear-AzContext -Force prior to connecting, error remains.

PS C:\Users\sqlsolver> Connect-AzAccount -ServicePrincipal -TenantId e19b1234-5678-490c-9dc7-58818xyz2xyz -CertificateThumbprint $certThumb -ApplicationId 7f7e249b-2e12-4b34-a5bb-056789b4d1ef
DEBUG: 12:23:43 PM - ConnectAzureRmAccountCommand begin processing with ParameterSet 'ServicePrincipalCertificateWithSubscriptionId'.
DEBUG: 12:23:43 PM - using account id 'myId@myMSFT.com'...
DEBUG: 12:23:43 PM - Autosave setting from startup session: 'CurrentUser'
DEBUG: 12:23:43 PM - No autosave setting detected in environment variable 'AzContextAutoSave'.
DEBUG: 12:23:43 PM - Using Autosave scope 'CurrentUser'
DEBUG: [Common.Authentication]: Authenticating using configuration values: Domain: 'e19b1234-5678-490c-9dc7-58818xyz2xyz', Endpoint: 'https://login.microsoftonline.com/', ClientId: '1950a258-227b-4e31-a9cf-717495945fc2', ClientRedirect: 'urn:ietf:wg:oauth:2.0:oob', ResourceClientUri: 'https://management.core.windows.net/', ValidateAuthority: 'True'
DEBUG: [ADAL]: Information: 2019-07-08T19:23:43.7560060Z: 69c25e6f-077e-4894-901a-2d4e4a084f47 - LoggerBase.cs: ADAL PCL.CoreCLR with assembly version '3.19.2.6005', file version '3.19.50302.0130' and informational version '2a8bec6c4c76d0c1ef819b55bdc3cda2d2605056' is running...

DEBUG: [ADAL]: Information: 2019-07-08T19:23:43.7561144Z: 69c25e6f-077e-4894-901a-2d4e4a084f47 - LoggerBase.cs: ADAL PCL.CoreCLR with assembly version '3.19.2.6005', file version '3.19.50302.0130' and informational version '2a8bec6c4c76d0c1ef819b55bdc3cda2d2605056' is running...

DEBUG: [ADAL]: Information: 2019-07-08T19:23:43.7561903Z: 69c25e6f-077e-4894-901a-2d4e4a084f47 - LoggerBase.cs: === Token Acquisition started:
        CacheType: null
        Authentication Target: Client
        , Authority Host: login.microsoftonline.com

DEBUG: [ADAL]: Information: 2019-07-08T19:23:43.7562478Z: 69c25e6f-077e-4894-901a-2d4e4a084f47 - LoggerBase.cs: === Token Acquisition started:
        Authority: https://login.microsoftonline.com/e19b1234-5678-490c-9dc7-58818xyz2xyz/
        Resource: https://management.core.windows.net/
        ClientId: 7f7e249b-2e12-4b34-a5bb-056789b4d1ef
        CacheType: null
        Authentication Target: Client

DEBUG: [ADAL]: Verbose: 2019-07-08T19:23:43.7563730Z: 69c25e6f-077e-4894-901a-2d4e4a084f47 - LoggerBase.cs: Loading from cache.

DEBUG: [ADAL]: Verbose: 2019-07-08T19:23:43.7564462Z: 69c25e6f-077e-4894-901a-2d4e4a084f47 - LoggerBase.cs: Loading from cache.

DEBUG: [ADAL]: Information: 2019-07-08T19:23:43.7595834Z: 00000000-0000-0000-0000-000000000000 - LoggerBase.cs: Deserialized 12 items to token cache.

DEBUG: [ADAL]: Verbose: 2019-07-08T19:23:43.7597843Z: 69c25e6f-077e-4894-901a-2d4e4a084f47 - LoggerBase.cs: Looking up cache for a token...

DEBUG: [ADAL]: Verbose: 2019-07-08T19:23:43.7598718Z: 69c25e6f-077e-4894-901a-2d4e4a084f47 - LoggerBase.cs: Looking up cache for a token...

DEBUG: [ADAL]: Information: 2019-07-08T19:23:43.7599582Z: 69c25e6f-077e-4894-901a-2d4e4a084f47 - LoggerBase.cs: No matching token was found in the cache

DEBUG: [ADAL]: Information: 2019-07-08T19:23:43.7600245Z: 69c25e6f-077e-4894-901a-2d4e4a084f47 - LoggerBase.cs: No matching token was found in the cache

DEBUG: [ADAL]: Verbose: 2019-07-08T19:23:43.7600891Z: 69c25e6f-077e-4894-901a-2d4e4a084f47 - LoggerBase.cs: Looking up cache for a token...

DEBUG: [ADAL]: Verbose: 2019-07-08T19:23:43.7601518Z: 69c25e6f-077e-4894-901a-2d4e4a084f47 - LoggerBase.cs: Looking up cache for a token...

DEBUG: [ADAL]: Information: 2019-07-08T19:23:43.7602165Z: 69c25e6f-077e-4894-901a-2d4e4a084f47 - LoggerBase.cs: No matching token was found in the cache

DEBUG: [ADAL]: Information: 2019-07-08T19:23:43.7603050Z: 69c25e6f-077e-4894-901a-2d4e4a084f47 - LoggerBase.cs: No matching token was found in the cache

DEBUG: [ADAL]: Verbose: 2019-07-08T19:23:43.7603931Z: 69c25e6f-077e-4894-901a-2d4e4a084f47 - LoggerBase.cs: Looking up cache for a token...

DEBUG: [ADAL]: Verbose: 2019-07-08T19:23:43.7604718Z: 69c25e6f-077e-4894-901a-2d4e4a084f47 - LoggerBase.cs: Looking up cache for a token...

DEBUG: [ADAL]: Information: 2019-07-08T19:23:43.7606177Z: 69c25e6f-077e-4894-901a-2d4e4a084f47 - LoggerBase.cs: No matching token was found in the cache

DEBUG: [ADAL]: Information: 2019-07-08T19:23:43.7607338Z: 69c25e6f-077e-4894-901a-2d4e4a084f47 - LoggerBase.cs: No matching token was found in the cache

DEBUG: [ADAL]: Verbose: 2019-07-08T19:23:43.7608132Z: 69c25e6f-077e-4894-901a-2d4e4a084f47 - LoggerBase.cs: Looking up cache for a token...

DEBUG: [ADAL]: Verbose: 2019-07-08T19:23:43.7608771Z: 69c25e6f-077e-4894-901a-2d4e4a084f47 - LoggerBase.cs: Looking up cache for a token...

DEBUG: [ADAL]: Information: 2019-07-08T19:23:43.7609442Z: 69c25e6f-077e-4894-901a-2d4e4a084f47 - LoggerBase.cs: No matching token was found in the cache

DEBUG: [ADAL]: Information: 2019-07-08T19:23:43.7610067Z: 69c25e6f-077e-4894-901a-2d4e4a084f47 - LoggerBase.cs: No matching token was found in the cache

DEBUG: [ADAL]: Verbose: 2019-07-08T19:23:43.7610704Z: 69c25e6f-077e-4894-901a-2d4e4a084f47 - LoggerBase.cs: Looking up cache for a token...

DEBUG: [ADAL]: Verbose: 2019-07-08T19:23:43.7611320Z: 69c25e6f-077e-4894-901a-2d4e4a084f47 - LoggerBase.cs: Looking up cache for a token...

DEBUG: [ADAL]: Information: 2019-07-08T19:23:43.7611964Z: 69c25e6f-077e-4894-901a-2d4e4a084f47 - LoggerBase.cs: No matching token was found in the cache

DEBUG: [ADAL]: Information: 2019-07-08T19:23:43.7612588Z: 69c25e6f-077e-4894-901a-2d4e4a084f47 - LoggerBase.cs: No matching token was found in the cache

DEBUG: [ADAL]: Verbose: 2019-07-08T19:23:43.7613252Z: 69c25e6f-077e-4894-901a-2d4e4a084f47 - LoggerBase.cs: Looking up cache for a token...

DEBUG: [ADAL]: Verbose: 2019-07-08T19:23:43.7613863Z: 69c25e6f-077e-4894-901a-2d4e4a084f47 - LoggerBase.cs: Looking up cache for a token...

DEBUG: [ADAL]: Information: 2019-07-08T19:23:43.7614516Z: 69c25e6f-077e-4894-901a-2d4e4a084f47 - LoggerBase.cs: No matching token was found in the cache

DEBUG: [ADAL]: Information: 2019-07-08T19:23:43.7615366Z: 69c25e6f-077e-4894-901a-2d4e4a084f47 - LoggerBase.cs: No matching token was found in the cache

DEBUG: [ADAL]: Error: 2019-07-08T19:23:43.7629557Z: 69c25e6f-077e-4894-901a-2d4e4a084f47 - LoggerBase.cs: Exception type: System.NullReferenceException
   at Microsoft.IdentityModel.Clients.ActiveDirectory.Internal.Platform.CryptographyHelper.SignWithCertificate(String message, X509Certificate2 certificate)
   at Microsoft.IdentityModel.Clients.ActiveDirectory.ClientAssertionCertificate.Sign(String message)
   at Microsoft.IdentityModel.Clients.ActiveDirectory.Internal.ClientCreds.JsonWebToken.Sign(IClientAssertionCertificate credential, Boolean sendX5C)
   at Microsoft.IdentityModel.Clients.ActiveDirectory.Internal.ClientCreds.ClientKey.AddToParameters(IDictionary`2 parameters)
   at Microsoft.IdentityModel.Clients.ActiveDirectory.Internal.DictionaryRequestParameters..ctor(String resource, ClientKey clientKey)
   at Microsoft.IdentityModel.Clients.ActiveDirectory.Internal.Flows.AcquireTokenHandlerBase.SendTokenRequestAsync()
   at Microsoft.IdentityModel.Clients.ActiveDirectory.Internal.Flows.AcquireTokenHandlerBase.CheckAndAcquireTokenUsingBrokerAsync()
   at Microsoft.IdentityModel.Clients.ActiveDirectory.Internal.Flows.AcquireTokenHandlerBase.RunAsync()

DEBUG: [ADAL]: Error: 2019-07-08T19:23:43.7632833Z: 69c25e6f-077e-4894-901a-2d4e4a084f47 - LoggerBase.cs: System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.IdentityModel.Clients.ActiveDirectory.Internal.Platform.CryptographyHelper.SignWithCertificate(String message, X509Certificate2 certificate)
   at Microsoft.IdentityModel.Clients.ActiveDirectory.ClientAssertionCertificate.Sign(String message)
   at Microsoft.IdentityModel.Clients.ActiveDirectory.Internal.ClientCreds.JsonWebToken.Sign(IClientAssertionCertificate credential, Boolean sendX5C)
   at Microsoft.IdentityModel.Clients.ActiveDirectory.Internal.ClientCreds.ClientKey.AddToParameters(IDictionary`2 parameters)
   at Microsoft.IdentityModel.Clients.ActiveDirectory.Internal.DictionaryRequestParameters..ctor(String resource, ClientKey clientKey)
   at Microsoft.IdentityModel.Clients.ActiveDirectory.Internal.Flows.AcquireTokenHandlerBase.SendTokenRequestAsync()
   at Microsoft.IdentityModel.Clients.ActiveDirectory.Internal.Flows.AcquireTokenHandlerBase.CheckAndAcquireTokenUsingBrokerAsync()
   at Microsoft.IdentityModel.Clients.ActiveDirectory.Internal.Flows.AcquireTokenHandlerBase.RunAsync()

Connect-AzAccount : Object reference not set to an instance of an object.
At line:1 char:1
+ Connect-AzAccount -ServicePrincipal -TenantId e19b1234-5678-490c-9dc7 ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : CloseError: (:) [Connect-AzAccount], NullReferenceException
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.Profile.ConnectAzureRmAccountCommand

DEBUG: AzureQoSEvent: CommandName - Connect-AzAccount; IsSuccess - False; Duration - 00:00:00.6825887; Exception - System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.IdentityModel.Clients.ActiveDirectory.Internal.Platform.CryptographyHelper.SignWithCertificate(String message, X509Certificate2 certificate)
   at Microsoft.IdentityModel.Clients.ActiveDirectory.ClientAssertionCertificate.Sign(String message)
   at Microsoft.IdentityModel.Clients.ActiveDirectory.Internal.ClientCreds.JsonWebToken.Sign(IClientAssertionCertificate credential, Boolean sendX5C)
   at Microsoft.IdentityModel.Clients.ActiveDirectory.Internal.ClientCreds.ClientKey.AddToParameters(IDictionary`2 parameters)
   at Microsoft.IdentityModel.Clients.ActiveDirectory.Internal.DictionaryRequestParameters..ctor(String resource, ClientKey clientKey)
   at Microsoft.IdentityModel.Clients.ActiveDirectory.Internal.Flows.AcquireTokenHandlerBase.SendTokenRequestAsync()
   at Microsoft.IdentityModel.Clients.ActiveDirectory.Internal.Flows.AcquireTokenHandlerBase.CheckAndAcquireTokenUsingBrokerAsync()
   at Microsoft.IdentityModel.Clients.ActiveDirectory.Internal.Flows.AcquireTokenHandlerBase.RunAsync()
   at Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext.AcquireTokenForClientCommonAsync(String resource, ClientKey clientKey)
   at Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext.AcquireTokenAsync(String resource, IClientAssertionCertificate clientCertificate)
   at Microsoft.Azure.Commands.Common.Authentication.ServicePrincipalTokenProvider.AcquireTokenWithCertificate(AdalConfiguration config, String appId, String thumbprint)
   at Microsoft.Azure.Commands.Common.Authentication.ServicePrincipalTokenProvider.GetAccessTokenWithCertificate(AdalConfiguration config, String clientId, String certificateThumbprint, String credentialType)
   at Microsoft.Azure.Commands.Common.Authentication.AdalTokenProvider.GetAccessTokenWithCertificate(AdalConfiguration config, String clientId, String certificate, String credentialType)
   at Microsoft.Azure.Commands.Common.Authentication.Factories.AuthenticationFactory.Authenticate(IAzureAccount account, IAzureEnvironment environment, String tenant, SecureString password, String promptBehavior, Action`1 promptAction, IAzureTokenCache tokenCache, String resourceId)
   at Microsoft.Azure.Commands.ResourceManager.Common.RMProfileClient.AcquireAccessToken(IAzureAccount account, IAzureEnvironment environment, String tenantId, SecureString password, String promptBehavior, Action`1 promptAction)
   at Microsoft.Azure.Commands.ResourceManager.Common.RMProfileClient.Login(IAzureAccount account, IAzureEnvironment environment, String tenantId, String subscriptionId, String subscriptionName, SecureString password, Boolean skipValidation, Action`1 promptAction, String name, Boolean shouldPopulateContextList)
   at Microsoft.Azure.Commands.Profile.ConnectAzureRmAccountCommand.<>c__DisplayClass92_0.<ExecuteCmdlet>b__0(AzureRmProfile localProfile, RMProfileClient profileClient, String name)
   at Microsoft.Azure.Commands.Profile.ConnectAzureRmAccountCommand.<>c__DisplayClass94_0.<SetContextWithOverwritePrompt>b__0(AzureRmProfile prof, RMProfileClient client)
   at Microsoft.Azure.Commands.Profile.Common.AzureContextModificationCmdlet.ModifyContext(Action`2 contextAction)
   at Microsoft.Azure.Commands.Profile.ConnectAzureRmAccountCommand.SetContextWithOverwritePrompt(Action`3 setContextAction)
   at Microsoft.Azure.Commands.Profile.ConnectAzureRmAccountCommand.ExecuteCmdlet()
   at Microsoft.WindowsAzure.Commands.Utilities.Common.CmdletExtensions.<>c__3`1.<ExecuteSynchronouslyOrAsJob>b__3_0(T c)
   at Microsoft.WindowsAzure.Commands.Utilities.Common.CmdletExtensions.ExecuteSynchronouslyOrAsJob[T](T cmdlet, Action`1 executor)
   at Microsoft.WindowsAzure.Commands.Utilities.Common.CmdletExtensions.ExecuteSynchronouslyOrAsJob[T](T cmdlet)
   at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord();
DEBUG: Finish sending metric.
DEBUG: 12:23:44 PM - ConnectAzureRmAccountCommand end processing.
DEBUG: 12:23:44 PM - ConnectAzureRmAccountCommand end processing.
PS C:\Users\sqlsolver>
cormacpayne commented 5 years ago

@rafaci @sqlsolver it looks like this line is causing the issue -- the account that we receive from MSAL for service principal requests is null, so when we try to pull the user id, we get a null-reference exception. This issue will be fixed when we add MSAL support to our stable Az.Accounts module later this summer.

sqlsolver commented 5 years ago

@cormacpayne Is there a current workaround?

markcowl commented 5 years ago

@sqlsolver Unfortunately, the preview is only designed for user authentication. When this becomes geenrally available, there will be full support for all supported authentications cenarios, incuding this one.

sqlsolver commented 5 years ago

@markcowl @cormacpayne I see there was a 7/30 milestone. Any progress to report? Bug is directly affecting a good-sized Azure data warehouse implementation.

markcowl commented 5 years ago

@sqlsolver this is still preview, we expect that this will GA sometime later this summer.

erich-wang commented 4 years ago

move to next milestone since MSAL release is delayed

erich-wang commented 4 years ago

Assign to Yeming to track the release of MSAL

egulatee commented 4 years ago

I am also stuck on the same issue. So far I've been using my own account to run powershell but would like to begin using a Service Principal.

I do not believe I am using any Preview modules.
Using docker & powershell 6.2.4

    Directory: /root/.local/share/powershell/Modules

ModuleType Version    Name                                PSEdition ExportedCom
                                                                    mands
---------- -------    ----                                --------- -----------
Script     1.7.1      Az.Accounts                         Core,Desk {Disable-A…
Script     0.2.10     Az.Blueprint                        Core,Desk {Get-AzBlu…
Script     1.10.0     Az.Resources                        Core,Desk {Get-AzPro…

    Directory: /opt/microsoft/powershell/6.2.4/Modules

ModuleType Version    Name                                PSEdition ExportedCom
                                                                    mands
---------- -------    ----                                --------- -----------
Manifest   1.2.3.0    Microsoft.PowerShell.Archive        Desk      {Compress-…
Manifest   6.1.0.0    Microsoft.PowerShell.Host           Core      {Start-Tra…
Manifest   6.1.0.0    Microsoft.PowerShell.Management     Core      {Add-Conte…
Manifest   6.1.0.0    Microsoft.PowerShell.Security       Core      {Get-Crede…
Manifest   6.1.0.0    Microsoft.PowerShell.Utility        Core      {Export-Al…
Script     1.3.2      PackageManagement                   Desk      {Find-Pack…
Script     2.1.3      PowerShellGet                       Desk      {Find-Comm…
Script     0.0        PSDesiredStateConfiguration         Desk      {Generate-…
Script     2.0.0      PSReadLine                          Desk      {Get-PSRea…
Binary     1.1.2      ThreadJob                           Desk      Start-Thre…

I import the certificate and try to use it.

    $certpath = './Azure/Credentials/AzureSecurityPrincipal.cer'
    $certexists = Test-Path $certpath -PathType Leaf
    if ($certexists)
    {
        Write-Host 'Certificate exists'
    }
    else
    {
        Write-Host 'Certificate doesnt exist'
    }

    Write-Debug "Import Credentials"

    # Import a PFX
    $storeName = [System.Security.Cryptography.X509Certificates.StoreName]::My 
    $storeLocation = [System.Security.Cryptography.X509Certificates.StoreLocation]::CurrentUser 
    $store = [System.Security.Cryptography.X509Certificates.X509Store]::new($storeName, $storeLocation) 
    $certPath = $certpath
    $credentials = Get-Credential -Message "Provide PFX private key password"
    $flag = [System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]::Exportable 
    $certificate = [System.Security.Cryptography.X509Certificates.X509Certificate2]::new($certPath, $credentials.Password, $flag) 
    $store.Open([System.Security.Cryptography.X509Certificates.OpenFlags]::ReadWrite) 
    $store.Add($Certificate) 
    $store.Close()

    Write-Information "Imported Credentials"

    Write-Host "Certificate=" $certificate

    Write-Debug "Logging in"

    $thumbprint =       <THUMBPRINT>
    $applicationid =    <APPLICATIONID>
    $tenantid =         <TENANTID>
    Connect-AzAccount  -Tenant $tenantid -CertificateThumbprint $thumbprint -ApplicationId $applicationid -ServicePrincipal
DEBUG: Import Credentials

DEBUG: Logging in
DEBUG: 20:30:17 - ConnectAzureRmAccountCommand begin processing with ParameterSet 'ServicePrincipalCertificateWithSubscriptionId'.
DEBUG: 20:30:17 - Autosave setting from startup session: 'CurrentUser'
DEBUG: 20:30:17 - No autosave setting detected in environment variable 'AzContextAutoSave'. 
DEBUG: 20:30:17 - Using Autosave scope 'CurrentUser'
DEBUG: [Common.Authentication]: Authenticating using configuration values: Domain: '23b2cc00-e776-44cb-a980-c7c90c455026', Endpoint: 'https://login.microsoftonline.com/', ClientId: '1950a258-227b-4e31-a9cf-717495945fc2', ClientRedirect: 'urn:ietf:wg:oauth:2.0:oob', ResourceClientUri: 'https://management.core.windows.net/', ValidateAuthority: 'True'
DEBUG: [ADAL]: Information: 2020-02-06T20:30:17.6377437Z: 62526f1e-61f4-438e-a458-904705112700 - LoggerBase.cs: ADAL PCL.CoreCLR with assembly version '3.19.2.6005', file version '3.19.50302.0130' and informational version '2a8bec6c4c76d0c1ef819b55bdc3cda2d2605056' is running...

DEBUG: [ADAL]: Information: 2020-02-06T20:30:17.6380980Z: 62526f1e-61f4-438e-a458-904705112700 - LoggerBase.cs: ADAL PCL.CoreCLR with assembly version '3.19.2.6005', file version '3.19.50302.0130' and informational version '2a8bec6c4c76d0c1ef819b55bdc3cda2d2605056' is running...

DEBUG: [ADAL]: Information: 2020-02-06T20:30:17.6387469Z: 62526f1e-61f4-438e-a458-904705112700 - LoggerBase.cs: === Token Acquisition started: 
    CacheType: null
    Authentication Target: Client
    , Authority Host: login.microsoftonline.com

DEBUG: [ADAL]: Information: 2020-02-06T20:30:17.6389047Z: 62526f1e-61f4-438e-a458-904705112700 - LoggerBase.cs: === Token Acquisition started:
    Authority: https://login.microsoftonline.com/23b2cc00-e776-44cb-a980-c7c90c455026/
    Resource: https://management.core.windows.net/
    ClientId: 90d42895-1b0e-43bd-ae20-f4baa9c60f61
    CacheType: null
    Authentication Target: Client

DEBUG: [ADAL]: Verbose: 2020-02-06T20:30:17.8976609Z: 62526f1e-61f4-438e-a458-904705112700 - LoggerBase.cs: Loading from cache.

DEBUG: [ADAL]: Verbose: 2020-02-06T20:30:17.8980032Z: 62526f1e-61f4-438e-a458-904705112700 - LoggerBase.cs: Loading from cache.

DEBUG: [ADAL]: Information: 2020-02-06T20:30:17.9022991Z: 00000000-0000-0000-0000-000000000000 - LoggerBase.cs: Deserialized 0 items to token cache.

DEBUG: [ADAL]: Verbose: 2020-02-06T20:30:17.9102306Z: 62526f1e-61f4-438e-a458-904705112700 - LoggerBase.cs: Looking up cache for a token...

DEBUG: [ADAL]: Verbose: 2020-02-06T20:30:17.9105195Z: 62526f1e-61f4-438e-a458-904705112700 - LoggerBase.cs: Looking up cache for a token...

DEBUG: [ADAL]: Information: 2020-02-06T20:30:17.9182789Z: 62526f1e-61f4-438e-a458-904705112700 - LoggerBase.cs: No matching token was found in the cache

DEBUG: [ADAL]: Information: 2020-02-06T20:30:17.9184308Z: 62526f1e-61f4-438e-a458-904705112700 - LoggerBase.cs: No matching token was found in the cache

DEBUG: [ADAL]: Verbose: 2020-02-06T20:30:17.9184979Z: 62526f1e-61f4-438e-a458-904705112700 - LoggerBase.cs: Looking up cache for a token...

DEBUG: [ADAL]: Verbose: 2020-02-06T20:30:17.9185523Z: 62526f1e-61f4-438e-a458-904705112700 - LoggerBase.cs: Looking up cache for a token...

DEBUG: [ADAL]: Information: 2020-02-06T20:30:17.9186342Z: 62526f1e-61f4-438e-a458-904705112700 - LoggerBase.cs: No matching token was found in the cache

DEBUG: [ADAL]: Information: 2020-02-06T20:30:17.9186863Z: 62526f1e-61f4-438e-a458-904705112700 - LoggerBase.cs: No matching token was found in the cache

DEBUG: [ADAL]: Verbose: 2020-02-06T20:30:17.9187416Z: 62526f1e-61f4-438e-a458-904705112700 - LoggerBase.cs: Looking up cache for a token...

DEBUG: [ADAL]: Verbose: 2020-02-06T20:30:17.9187909Z: 62526f1e-61f4-438e-a458-904705112700 - LoggerBase.cs: Looking up cache for a token...

DEBUG: [ADAL]: Information: 2020-02-06T20:30:17.9190763Z: 62526f1e-61f4-438e-a458-904705112700 - LoggerBase.cs: No matching token was found in the cache

DEBUG: [ADAL]: Information: 2020-02-06T20:30:17.9191343Z: 62526f1e-61f4-438e-a458-904705112700 - LoggerBase.cs: No matching token was found in the cache

DEBUG: [ADAL]: Verbose: 2020-02-06T20:30:17.9191882Z: 62526f1e-61f4-438e-a458-904705112700 - LoggerBase.cs: Looking up cache for a token...

DEBUG: [ADAL]: Verbose: 2020-02-06T20:30:17.9192340Z: 62526f1e-61f4-438e-a458-904705112700 - LoggerBase.cs: Looking up cache for a token...

DEBUG: [ADAL]: Information: 2020-02-06T20:30:17.9193023Z: 62526f1e-61f4-438e-a458-904705112700 - LoggerBase.cs: No matching token was found in the cache

DEBUG: [ADAL]: Information: 2020-02-06T20:30:17.9193493Z: 62526f1e-61f4-438e-a458-904705112700 - LoggerBase.cs: No matching token was found in the cache

DEBUG: [ADAL]: Verbose: 2020-02-06T20:30:17.9194007Z: 62526f1e-61f4-438e-a458-904705112700 - LoggerBase.cs: Looking up cache for a token...

DEBUG: [ADAL]: Verbose: 2020-02-06T20:30:17.9194454Z: 62526f1e-61f4-438e-a458-904705112700 - LoggerBase.cs: Looking up cache for a token...

DEBUG: [ADAL]: Information: 2020-02-06T20:30:17.9195130Z: 62526f1e-61f4-438e-a458-904705112700 - LoggerBase.cs: No matching token was found in the cache

DEBUG: [ADAL]: Information: 2020-02-06T20:30:17.9199881Z: 62526f1e-61f4-438e-a458-904705112700 - LoggerBase.cs: No matching token was found in the cache

DEBUG: [ADAL]: Verbose: 2020-02-06T20:30:17.9200498Z: 62526f1e-61f4-438e-a458-904705112700 - LoggerBase.cs: Looking up cache for a token...

DEBUG: [ADAL]: Verbose: 2020-02-06T20:30:17.9219423Z: 62526f1e-61f4-438e-a458-904705112700 - LoggerBase.cs: Looking up cache for a token...

DEBUG: [ADAL]: Information: 2020-02-06T20:30:17.9242494Z: 62526f1e-61f4-438e-a458-904705112700 - LoggerBase.cs: No matching token was found in the cache

DEBUG: [ADAL]: Information: 2020-02-06T20:30:17.9243268Z: 62526f1e-61f4-438e-a458-904705112700 - LoggerBase.cs: No matching token was found in the cache

DEBUG: [ADAL]: Error: 2020-02-06T20:30:17.9457881Z: 62526f1e-61f4-438e-a458-904705112700 - LoggerBase.cs: Exception type: System.NullReferenceException
   at Microsoft.IdentityModel.Clients.ActiveDirectory.Internal.Platform.CryptographyHelper.SignWithCertificate(String message, X509Certificate2 certificate)
   at Microsoft.IdentityModel.Clients.ActiveDirectory.ClientAssertionCertificate.Sign(String message)
   at Microsoft.IdentityModel.Clients.ActiveDirectory.Internal.ClientCreds.JsonWebToken.Sign(IClientAssertionCertificate credential, Boolean sendX5C)
   at Microsoft.IdentityModel.Clients.ActiveDirectory.Internal.ClientCreds.ClientKey.AddToParameters(IDictionary`2 parameters)
   at Microsoft.IdentityModel.Clients.ActiveDirectory.Internal.DictionaryRequestParameters..ctor(String resource, ClientKey clientKey)
   at Microsoft.IdentityModel.Clients.ActiveDirectory.Internal.Flows.AcquireTokenHandlerBase.SendTokenRequestAsync()
   at Microsoft.IdentityModel.Clients.ActiveDirectory.Internal.Flows.AcquireTokenHandlerBase.CheckAndAcquireTokenUsingBrokerAsync()
   at Microsoft.IdentityModel.Clients.ActiveDirectory.Internal.Flows.AcquireTokenHandlerBase.RunAsync()

DEBUG: [ADAL]: Error: 2020-02-06T20:30:17.9463398Z: 62526f1e-61f4-438e-a458-904705112700 - LoggerBase.cs: System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.IdentityModel.Clients.ActiveDirectory.Internal.Platform.CryptographyHelper.SignWithCertificate(String message, X509Certificate2 certificate)
   at Microsoft.IdentityModel.Clients.ActiveDirectory.ClientAssertionCertificate.Sign(String message)
   at Microsoft.IdentityModel.Clients.ActiveDirectory.Internal.ClientCreds.JsonWebToken.Sign(IClientAssertionCertificate credential, Boolean sendX5C)
   at Microsoft.IdentityModel.Clients.ActiveDirectory.Internal.ClientCreds.ClientKey.AddToParameters(IDictionary`2 parameters)
   at Microsoft.IdentityModel.Clients.ActiveDirectory.Internal.DictionaryRequestParameters..ctor(String resource, ClientKey clientKey)
   at Microsoft.IdentityModel.Clients.ActiveDirectory.Internal.Flows.AcquireTokenHandlerBase.SendTokenRequestAsync()
   at Microsoft.IdentityModel.Clients.ActiveDirectory.Internal.Flows.AcquireTokenHandlerBase.CheckAndAcquireTokenUsingBrokerAsync()
   at Microsoft.IdentityModel.Clients.ActiveDirectory.Internal.Flows.AcquireTokenHandlerBase.RunAsync()

Connect-AzAccount : Object reference not set to an instance of an object.
At /tmp/Azure/Powershell/Authentication/ConnectUsingServicePrincipal.psm1:40 char:2
+     Connect-AzAccount  -Tenant $tenantid -CertificateThumbprint $thum ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : CloseError: (:) [Connect-AzAccount], NullReferenceException
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.Profile.ConnectAzureRmAccountCommand

DEBUG: AzureQoSEvent: CommandName - Connect-AzAccount; IsSuccess - False; Duration - 00:00:00.4244562; Exception - System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.IdentityModel.Clients.ActiveDirectory.Internal.Platform.CryptographyHelper.SignWithCertificate(String message, X509Certificate2 certificate)
   at Microsoft.IdentityModel.Clients.ActiveDirectory.ClientAssertionCertificate.Sign(String message)
   at Microsoft.IdentityModel.Clients.ActiveDirectory.Internal.ClientCreds.JsonWebToken.Sign(IClientAssertionCertificate credential, Boolean sendX5C)
   at Microsoft.IdentityModel.Clients.ActiveDirectory.Internal.ClientCreds.ClientKey.AddToParameters(IDictionary`2 parameters)
   at Microsoft.IdentityModel.Clients.ActiveDirectory.Internal.DictionaryRequestParameters..ctor(String resource, ClientKey clientKey)
   at Microsoft.IdentityModel.Clients.ActiveDirectory.Internal.Flows.AcquireTokenHandlerBase.SendTokenRequestAsync()
   at Microsoft.IdentityModel.Clients.ActiveDirectory.Internal.Flows.AcquireTokenHandlerBase.CheckAndAcquireTokenUsingBrokerAsync()
   at Microsoft.IdentityModel.Clients.ActiveDirectory.Internal.Flows.AcquireTokenHandlerBase.RunAsync()
   at Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext.AcquireTokenForClientCommonAsync(String resource, ClientKey clientKey)
   at Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext.AcquireTokenAsync(String resource, IClientAssertionCertificate clientCertificate)
   at Microsoft.Azure.Commands.Common.Authentication.ServicePrincipalTokenProvider.AcquireTokenWithCertificate(AdalConfiguration config, String appId, String thumbprint)
   at Microsoft.Azure.Commands.Common.Authentication.ServicePrincipalTokenProvider.GetAccessTokenWithCertificate(AdalConfiguration config, String clientId, String certificateThumbprint, String credentialType)
   at Microsoft.Azure.Commands.Common.Authentication.AdalTokenProvider.GetAccessTokenWithCertificate(AdalConfiguration config, String clientId, String certificate, String credentialType)
   at Microsoft.Azure.Commands.Common.Authentication.Factories.AuthenticationFactory.Authenticate(IAzureAccount account, IAzureEnvironment environment, String tenant, SecureString password, String promptBehavior, Action`1 promptAction, IAzureTokenCache tokenCache, String resourceId)
   at Microsoft.Azure.Commands.ResourceManager.Common.RMProfileClient.AcquireAccessToken(IAzureAccount account, IAzureEnvironment environment, String tenantId, SecureString password, String promptBehavior, Action`1 promptAction)
   at Microsoft.Azure.Commands.ResourceManager.Common.RMProfileClient.Login(IAzureAccount account, IAzureEnvironment environment, String tenantId, String subscriptionId, String subscriptionName, SecureString password, Boolean skipValidation, Action`1 promptAction, String name, Boolean shouldPopulateContextList)
   at Microsoft.Azure.Commands.Profile.ConnectAzureRmAccountCommand.<>c__DisplayClass92_0.<ExecuteCmdlet>b__0(AzureRmProfile localProfile, RMProfileClient profileClient, String name)
   at Microsoft.Azure.Commands.Profile.ConnectAzureRmAccountCommand.<>c__DisplayClass94_0.<SetContextWithOverwritePrompt>b__0(AzureRmProfile prof, RMProfileClient client)
   at Microsoft.Azure.Commands.Profile.Common.AzureContextModificationCmdlet.ModifyContext(Action`2 contextAction)
   at Microsoft.Azure.Commands.Profile.ConnectAzureRmAccountCommand.SetContextWithOverwritePrompt(Action`3 setContextAction)
   at Microsoft.Azure.Commands.Profile.ConnectAzureRmAccountCommand.ExecuteCmdlet()
   at Microsoft.WindowsAzure.Commands.Utilities.Common.CmdletExtensions.<>c__3`1.<ExecuteSynchronouslyOrAsJob>b__3_0(T c)
   at Microsoft.WindowsAzure.Commands.Utilities.Common.CmdletExtensions.ExecuteSynchronouslyOrAsJob[T](T cmdlet, Action`1 executor)
   at Microsoft.WindowsAzure.Commands.Utilities.Common.CmdletExtensions.ExecuteSynchronouslyOrAsJob[T](T cmdlet)
   at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord();
DEBUG: Finish sending metric.
DEBUG: 20:30:18 - ConnectAzureRmAccountCommand end processing.
DEBUG: 20:30:18 - ConnectAzureRmAccountCommand end processing.
ricohomewood commented 4 years ago

@isra-fel @cormacpayne I'm getting this error on the stable version of Az.Accounts 1.7.5 have we merged the bug into this stable version? This error is also being thrown using the Azure DevOps Azure Powershell task ... this would denote a bigger issue as the powershell tasks can't even complete a connection to Azure in the context of a Service Principle:

2020-05-14T12:45:13.3952701Z ##[debug]Imported module version: 1.7.5
2020-05-14T12:45:13.4007834Z ##[debug]Leaving Import-AzModule.
2020-05-14T12:45:13.4024490Z ##[debug]Initializing Az Module.
2020-05-14T12:45:13.4170246Z ##[debug]AZURE_HTTP_USER_AGENT: 'VSTS_7a5a84ac-460f-4c04-b579-db5d7ca4ecfc_Release__8633_31835_1'
2020-05-14T12:45:13.4204558Z ##[debug]Entering Set-UserAgent_Core.
2020-05-14T12:45:13.4270350Z ##[debug] UserAgent: 'VSTS_7a5a84ac-460f-4c04-b579-db5d7ca4ecfc_Release__8633_31835_1'
2020-05-14T12:45:13.4318137Z ##[debug]Leaving Set-UserAgent_Core.
2020-05-14T12:45:13.4322958Z ##[command]Clear-AzContext -Scope Process
2020-05-14T12:45:34.8732205Z ##[command]Clear-AzContext -Scope CurrentUser -Force -ErrorAction SilentlyContinue
2020-05-14T12:45:56.0025809Z ##[command]Connect-AzAccount -ServicePrincipal -Tenant *** -Credential System.Management.Automation.PSCredential -Environment AzureCloud @processScope
2020-05-14T12:46:57.1634043Z ##[error]Object reference not set to an instance of an object.
2020-05-14T12:46:57.1643420Z ##[debug]Processed: ##vso[task.logissue type=error]Object reference not set to an instance of an object.
2020-05-14T12:46:57.1864010Z ##[debug]Leaving Initialize-AzModule.
2020-05-14T12:46:57.1889614Z ##[error]Initializing Az module failed: For troubleshooting, refer: https://aka.ms/azurepowershelltroubleshooting
2020-05-14T12:46:57.1891082Z ##[debug]Processed: ##vso[task.logissue type=error]Initializing Az module failed: For troubleshooting, refer: https://aka.ms/azurepowershelltroubleshooting
2020-05-14T12:46:57.1934210Z ##[debug]Caught exception from task script.
2020-05-14T12:46:57.1962032Z ##[debug]Error record:
2020-05-14T12:46:57.2694348Z ##[debug]There was an error with the service principal used for the deployment.
2020-05-14T12:46:57.2705041Z ##[debug]At E:\agent4\_work\_tasks\AzurePowerShell_72a1931b-effb-4d2e-8fd8-f8472a07cb62\4.168.0\ps_modules\VstsAzureHelpers_\InitializeAzModuleFunctions.ps1:128 char:13
2020-05-14T12:46:57.2715524Z ##[debug]+             throw (New-Object System.Exception((Get-VstsLocString -Ke ...
2020-05-14T12:46:57.2726452Z ##[debug]+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2020-05-14T12:46:57.2737638Z ##[debug]    + CategoryInfo          : OperationStopped: (:) [], Exception
2020-05-14T12:46:57.2747968Z ##[debug]    + FullyQualifiedErrorId : There was an error with the service principal used for the deployment.
2020-05-14T12:46:57.2757788Z ##[debug] 
2020-05-14T12:46:57.2776054Z ##[debug]Script stack trace:
2020-05-14T12:46:57.2811856Z ##[debug]at Initialize-AzSubscription, E:\agent4\_work\_tasks\AzurePowerShell_72a1931b-effb-4d2e-8fd8-f8472a07cb62\4.168.0\ps_modules\VstsAzureHelpers_\InitializeAzModuleFunctions.ps1: line 128
2020-05-14T12:46:57.2822782Z ##[debug]at Initialize-AzModule, E:\agent4\_work\_tasks\AzurePowerShell_72a1931b-effb-4d2e-8fd8-f8472a07cb62\4.168.0\ps_modules\VstsAzureHelpers_\InitializeAzModuleFunctions.ps1: line 17
2020-05-14T12:46:57.2833867Z ##[debug]at <ScriptBlock>, E:\agent4\_work\_tasks\AzurePowerShell_72a1931b-effb-4d2e-8fd8-f8472a07cb62\4.168.0\azurepowershell.ps1: line 65
2020-05-14T12:46:57.2844832Z ##[debug]at <ScriptBlock>, <No file>: line 1
2020-05-14T12:46:57.2856064Z ##[debug]at <ScriptBlock>, <No file>: line 22
2020-05-14T12:46:57.2867721Z ##[debug]at <ScriptBlock>, <No file>: line 18
2020-05-14T12:46:57.2877621Z ##[debug]at <ScriptBlock>, <No file>: line 1
2020-05-14T12:46:57.2893733Z ##[debug]Exception:
2020-05-14T12:46:57.2934819Z ##[debug]System.Exception: There was an error with the service principal used for the deployment. ---> System.NullReferenceException: Object reference not set to an instance of an object.
2020-05-14T12:46:57.2944682Z ##[debug]   at Microsoft.IdentityModel.Clients.ActiveDirectory.Internal.Http.AdalHttpClient.<GetResponseAsync>d__22`1.MoveNext()
2020-05-14T12:46:57.2954781Z ##[debug]--- End of stack trace from previous location where exception was thrown ---
2020-05-14T12:46:57.2966506Z ##[debug]   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
2020-05-14T12:46:57.2977690Z ##[debug]   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
2020-05-14T12:46:57.2987879Z ##[debug]   at Microsoft.IdentityModel.Clients.ActiveDirectory.Internal.Http.AdalHttpClient.<GetResponseAsync>d__22`1.MoveNext()
2020-05-14T12:46:57.2997506Z ##[debug]--- End of stack trace from previous location where exception was thrown ---
2020-05-14T12:46:57.3007414Z ##[debug]   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
2020-05-14T12:46:57.3017125Z ##[debug]   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
2020-05-14T12:46:57.3027263Z ##[debug]   at Microsoft.IdentityModel.Clients.ActiveDirectory.Internal.Http.AdalHttpClient.<GetResponseAsync>d__21`1.MoveNext()
2020-05-14T12:46:57.3036928Z ##[debug]--- End of stack trace from previous location where exception was thrown ---
2020-05-14T12:46:57.3046655Z ##[debug]   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
2020-05-14T12:46:57.3056659Z ##[debug]   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
2020-05-14T12:46:57.3066387Z ##[debug]   at Microsoft.IdentityModel.Clients.ActiveDirectory.InstanceDiscovery.<DiscoverAsync>d__8.MoveNext()
2020-05-14T12:46:57.3076339Z ##[debug]--- End of stack trace from previous location where exception was thrown ---
2020-05-14T12:46:57.3086665Z ##[debug]   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
2020-05-14T12:46:57.3097151Z ##[debug]   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
2020-05-14T12:46:57.3106736Z ##[debug]   at Microsoft.IdentityModel.Clients.ActiveDirectory.InstanceDiscovery.<GetMetadataEntryAsync>d__5.MoveNext()
2020-05-14T12:46:57.3116403Z ##[debug]--- End of stack trace from previous location where exception was thrown ---
2020-05-14T12:46:57.3126177Z ##[debug]   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
2020-05-14T12:46:57.3136537Z ##[debug]   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
2020-05-14T12:46:57.3147850Z ##[debug]   at Microsoft.IdentityModel.Clients.ActiveDirectory.Internal.Instance.Authenticator.<UpdateFromTemplateAsync>d__47.MoveNext()
2020-05-14T12:46:57.3158229Z ##[debug]--- End of stack trace from previous location where exception was thrown ---
2020-05-14T12:46:57.3168689Z ##[debug]   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
2020-05-14T12:46:57.3178692Z ##[debug]   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
2020-05-14T12:46:57.3188627Z ##[debug]   at Microsoft.IdentityModel.Clients.ActiveDirectory.Internal.Flows.AcquireTokenHandlerBase.<PreRunAsync>d__64.MoveNext()
2020-05-14T12:46:57.3198732Z ##[debug]--- End of stack trace from previous location where exception was thrown ---
2020-05-14T12:46:57.3208678Z ##[debug]   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
2020-05-14T12:46:57.3220384Z ##[debug]   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
2020-05-14T12:46:57.3290732Z ##[debug]   at Microsoft.IdentityModel.Clients.ActiveDirectory.Internal.Flows.AcquireTokenHandlerBase.<RunAsync>d__57.MoveNext()
2020-05-14T12:46:57.3304543Z ##[debug]--- End of stack trace from previous location where exception was thrown ---
2020-05-14T12:46:57.3314467Z ##[debug]   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
2020-05-14T12:46:57.3324270Z ##[debug]   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
2020-05-14T12:46:57.3334758Z ##[debug]   at Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext.<AcquireTokenForClientCommonAsync>d__33.MoveNext()
2020-05-14T12:46:57.3344430Z ##[debug]--- End of stack trace from previous location where exception was thrown ---
2020-05-14T12:46:57.3354197Z ##[debug]   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
2020-05-14T12:46:57.3364816Z ##[debug]   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
2020-05-14T12:46:57.3374818Z ##[debug]   at Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext.<AcquireTokenAsync>d__59.MoveNext()
2020-05-14T12:46:57.3384784Z ##[debug]--- End of stack trace from previous location where exception was thrown ---
2020-05-14T12:46:57.3396356Z ##[debug]   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
2020-05-14T12:46:57.3405639Z ##[debug]   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
2020-05-14T12:46:57.3415726Z ##[debug]   at Microsoft.Azure.Commands.Common.Authentication.ServicePrincipalTokenProvider.AcquireTokenWithSecret(AdalConfiguration config, String appId, SecureString appKey)
2020-05-14T12:46:57.3425818Z ##[debug]   at Microsoft.Azure.Commands.Common.Authentication.ServicePrincipalTokenProvider.GetAccessToken(AdalConfiguration config, String promptBehavior, Action`1 promptAction, String userId, SecureString password, String credentialType)
2020-05-14T12:46:57.3436037Z ##[debug]   at Microsoft.Azure.Commands.Common.Authentication.Factories.AuthenticationFactory.Authenticate(IAzureAccount account, IAzureEnvironment environment, String tenant, SecureString password, String promptBehavior, Action`1 promptAction, IAzureTokenCache tokenCache, String resourceId)
2020-05-14T12:46:57.3446047Z ##[debug]   at Microsoft.Azure.Commands.ResourceManager.Common.RMProfileClient.AcquireAccessToken(IAzureAccount account, IAzureEnvironment environment, String tenantId, SecureString password, String promptBehavior, Action`1 promptAction)
2020-05-14T12:46:57.3455872Z ##[debug]   at Microsoft.Azure.Commands.ResourceManager.Common.RMProfileClient.Login(IAzureAccount account, IAzureEnvironment environment, String tenantId, String subscriptionId, String subscriptionName, SecureString password, Boolean skipValidation, Action`1 promptAction, String name, Boolean shouldPopulateContextList)
2020-05-14T12:46:57.3464948Z ##[debug]   at Microsoft.Azure.Commands.Profile.ConnectAzureRmAccountCommand.<>c__DisplayClass92_0.<ExecuteCmdlet>b__0(AzureRmProfile localProfile, RMProfileClient profileClient, String name)
2020-05-14T12:46:57.3474091Z ##[debug]   at Microsoft.Azure.Commands.Profile.Common.AzureContextModificationCmdlet.ModifyContext(Action`2 contextAction)
2020-05-14T12:46:57.3485156Z ##[debug]   at Microsoft.Azure.Commands.Profile.ConnectAzureRmAccountCommand.SetContextWithOverwritePrompt(Action`3 setContextAction)
2020-05-14T12:46:57.3496564Z ##[debug]   at Microsoft.Azure.Commands.Profile.ConnectAzureRmAccountCommand.ExecuteCmdlet()
2020-05-14T12:46:57.3506381Z ##[debug]   at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord()
2020-05-14T12:46:57.3515699Z ##[debug]   --- End of inner exception stack trace ---
2020-05-14T12:46:57.3531148Z ##[error]There was an error with the service principal used for the deployment.
2020-05-14T12:46:57.3532105Z ##[debug]Processed: ##vso[task.logissue type=error]There was an error with the service principal used for the deployment.
2020-05-14T12:46:57.3544984Z ##[debug]Processed: ##vso[task.complete result=Failed]
vamsidogiparthi commented 4 years ago

I am facing a similar issue. Not with Connect-AzAccount, but with all the other modules such as Get-AzureSubscription, Add-AzureAccount etc. Below are the list modules installed on my powershell and also the version of powershell i am running.

I tried to find a solution for this but couldn't able to do anything with it. I tried deleting all the modules and reinstall everything. But still it doesn't seem to work. When i use any az module command it says object not set.

PS C:\Users\vooo_> Get-AzureSubscription
Get-AzureSubscription: Object reference not set to an instance of an object.

PS C:\Users\vooo_> Add-AzureAccount
Add-AzureAccount: Object reference not set to an instance of an object.

PS C:\Users\vooo_> Get-AzureSubscription
Get-AzureSubscription: Object reference not set to an instance of an object.

Name                           Value
----                           -----
PSVersion                      7.0.2
PSEdition                      Core
GitCommitId                    7.0.2
OS                             Microsoft Windows 10.0.19041
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

    Directory: C:\Program Files\PowerShell\Modules

ModuleType Version    PreRelease Name                                PSEdition ExportedCommands
---------- -------    ---------- ----                                --------- ----------------
Script     4.3.0                 Az                                  Core,Desk
Script     1.9.0                 Az.Accounts                         Core,Desk {Disable-AzDataCollection, Disable-AzCo…
Script     1.1.1                 Az.Advisor                          Core,Desk {Get-AzAdvisorRecommendation, Enable-Az…
Script     1.1.2                 Az.Aks                              Core,Desk {Get-AzAks, New-AzAks, Remove-AzAks, Im…
Script     1.1.3                 Az.AnalysisServices                 Core,Desk {Resume-AzAnalysisServicesServer, Suspe…
Script     2.0.1                 Az.ApiManagement                    Core,Desk {Add-AzApiManagementApiToProduct, Add-A…
Script     1.1.0                 Az.ApplicationInsights              Core,Desk {Get-AzApplicationInsights, New-AzAppli…
Script     1.3.6                 Az.Automation                       Core,Desk {Get-AzAutomationHybridWorkerGroup, Rem…
Script     3.1.0                 Az.Batch                            Core,Desk {Remove-AzBatchAccount, Get-AzBatchAcco…
Script     1.0.3                 Az.Billing                          Core,Desk {Get-AzBillingInvoice, Get-AzBillingPer…
Script     1.4.3                 Az.Cdn                              Core,Desk {Get-AzCdnProfile, Get-AzCdnProfileSsoU…
Script     1.5.0                 Az.CognitiveServices                Core,Desk {Get-AzCognitiveServicesAccount, Get-Az…
Script     4.2.0                 Az.Compute                          Core,Desk {Remove-AzAvailabilitySet, Get-AzAvaila…
Script     1.0.3                 Az.ContainerInstance                Core,Desk {New-AzContainerGroup, Get-AzContainerG…
Script     1.1.1                 Az.ContainerRegistry                Core,Desk {New-AzContainerRegistry, Get-AzContain…
Script     1.1.0                 Az.DataBoxEdge                      Core,Desk {Get-AzDataBoxEdgeJob, Get-AzDataBoxEdg…
Script     1.8.2                 Az.DataFactory                      Core,Desk {Set-AzDataFactoryV2, Update-AzDataFact…
Script     1.0.2                 Az.DataLakeAnalytics                Core,Desk {Get-AzDataLakeAnalyticsDataSource, New…
Script     1.2.8                 Az.DataLakeStore                    Core,Desk {Get-AzDataLakeStoreTrustedIdProvider, …
Script     1.0.0                 Az.DataShare                        Core,Desk {New-AzDataShareAccount, Get-AzDataShar…
Script     1.1.0                 Az.DeploymentManager                Core,Desk {Get-AzDeploymentManagerArtifactSource,…
Script     1.0.0                 Az.DesktopVirtualization            Core,Desk {Disconnect-AzWvdUserSession, Get-AzWvd…
Script     1.0.2                 Az.DevTestLabs                      Core,Desk {Get-AzDtlAllowedVMSizesPolicy, Get-AzD…
Script     1.1.2                 Az.Dns                              Core,Desk {Get-AzDnsRecordSet, New-AzDnsRecordCon…
Script     1.2.3                 Az.EventGrid                        Core,Desk {New-AzEventGridTopic, Get-AzEventGridT…
Script     1.5.0                 Az.EventHub                         Core,Desk {New-AzEventHubNamespace, Get-AzEventHu…
Script     1.5.0                 Az.FrontDoor                        Core,Desk {New-AzFrontDoor, Get-AzFrontDoor, Set-…
Script     1.0.1                 Az.Functions                        Core,Desk {Get-AzFunctionApp, Get-AzFunctionAppAv…
Script     3.3.0                 Az.HDInsight                        Core,Desk {Get-AzHDInsightJob, New-AzHDInsightSqo…
Script     1.1.0                 Az.HealthcareApis                   Core,Desk {New-AzHealthcareApisService, Remove-Az…
Script     2.5.0                 Az.IotHub                           Core,Desk {Add-AzIotHubKey, Get-AzIotHubEventHubC…
Script     2.0.0                 Az.KeyVault                         Core,Desk {Add-AzKeyVaultCertificate, Update-AzKe…
Script     1.3.2                 Az.LogicApp                         Core,Desk {Get-AzIntegrationAccountAgreement, Get…
Script     1.1.3                 Az.MachineLearning                  Core,Desk {Move-AzMlCommitmentAssociation, Get-Az…
Script     1.0.0                 Az.Maintenance                      Core,Desk {Get-AzApplyUpdate, Get-AzConfiguration…
Script     1.0.2                 Az.ManagedServices                  Core,Desk {Get-AzManagedServicesAssignment, New-A…
Script     1.0.2                 Az.MarketplaceOrdering              Core,Desk {Get-AzMarketplaceTerms, Set-AzMarketpl…
Script     1.1.1                 Az.Media                            Core,Desk {Sync-AzMediaServiceStorageKey, Set-AzM…
Script     2.0.1                 Az.Monitor                          Core,Desk {Get-AzMetricDefinition, Get-AzMetric, …
Script     3.1.0                 Az.Network                          Core,Desk {Add-AzApplicationGatewayAuthentication…
Script     1.1.1                 Az.NotificationHubs                 Core,Desk {Get-AzNotificationHub, Get-AzNotificat…
Script     2.2.0                 Az.OperationalInsights              Core,Desk {New-AzOperationalInsightsAzureActivity…
Script     1.3.1                 Az.PolicyInsights                   Core,Desk {Get-AzPolicyEvent, Get-AzPolicyState, …
Script     1.1.2                 Az.PowerBIEmbedded                  Core,Desk {Remove-AzPowerBIWorkspaceCollection, G…
Script     1.0.3                 Az.PrivateDns                       Core,Desk {Get-AzPrivateDnsZone, Remove-AzPrivate…
Script     2.10.0                Az.RecoveryServices                 Core,Desk {Get-AzRecoveryServicesBackupProperty, …
Script     1.2.1                 Az.RedisCache                       Core,Desk {Remove-AzRedisCachePatchSchedule, New-…
Script     1.0.3                 Az.Relay                            Core,Desk {New-AzRelayNamespace, Get-AzRelayNames…
Script     2.2.0                 Az.Resources                        Core,Desk {Get-AzProviderOperation, Remove-AzRole…
Script     1.4.1                 Az.ServiceBus                       Core,Desk {New-AzServiceBusNamespace, Get-AzServi…
Script     2.1.0                 Az.ServiceFabric                    Core,Desk {Add-AzServiceFabricClientCertificate, …
Script     1.1.1                 Az.SignalR                          Core,Desk {New-AzSignalR, Get-AzSignalR, Get-AzSi…
Script     2.8.0                 Az.Sql                              Core,Desk {Get-AzSqlDatabaseTransparentDataEncryp…
Script     1.1.0                 Az.SqlVirtualMachine                Core,Desk {New-AzSqlVM, Get-AzSqlVM, Update-AzSql…
Script     2.2.0                 Az.Storage                          Core,Desk {Get-AzStorageAccount, Get-AzStorageAcc…
Script     1.2.3                 Az.StorageSync                      Core,Desk {Invoke-AzStorageSyncCompatibilityCheck…
Script     1.0.1                 Az.StreamAnalytics                  Core,Desk {Get-AzStreamAnalyticsFunction, Get-AzS…
Script     1.0.0                 Az.Support                          Core,Desk {Get-AzSupportService, Get-AzSupportPro…
Script     1.0.4                 Az.TrafficManager                   Core,Desk {Add-AzTrafficManagerCustomHeaderToEndp…
Script     1.10.0                Az.Websites                         Core,Desk {Get-AzAppServicePlan, Set-AzAppService…

    Directory: C:\program files\powershell\7\Modules

ModuleType Version    PreRelease Name                                PSEdition ExportedCommands
---------- -------    ---------- ----                                --------- ----------------
Manifest   7.0.0.0               CimCmdlets                          Core      {Get-CimAssociatedInstance, Get-CimClas…
Manifest   1.2.5                 Microsoft.PowerShell.Archive        Desk      {Compress-Archive, Expand-Archive}
Manifest   7.0.0.0               Microsoft.PowerShell.Diagnostics    Core      {Get-WinEvent, New-WinEvent, Get-Counte…
Manifest   7.0.0.0               Microsoft.PowerShell.Host           Core      {Start-Transcript, Stop-Transcript}
Manifest   7.0.0.0               Microsoft.PowerShell.Management     Core      {Add-Content, Clear-Content, Get-Clipbo…
Manifest   7.0.0.0               Microsoft.PowerShell.Security       Core      {Get-Acl, Set-Acl, Get-PfxCertificate, …
Manifest   7.0.0.0               Microsoft.PowerShell.Utility        Core      {Export-Alias, Get-Alias, Import-Alias,…
Manifest   7.0.0.0               Microsoft.WSMan.Management          Core      {Disable-WSManCredSSP, Enable-WSManCred…
Script     1.4.6                 PackageManagement                   Desk      {Find-Package, Get-Package, Get-Package…
Script     2.2.4                 PowerShellGet                       Desk      {Find-Command, Find-DSCResource, Find-M…
Script     2.0.5                 PSDesiredStateConfiguration         Core      {Configuration, New-DscChecksum, Get-Ds…
Script     7.0.0.0               PSDiagnostics                       Core      {Disable-PSTrace, Disable-PSWSManCombin…
Script     2.0.0                 PSReadLine                          Desk      {Get-PSReadLineKeyHandler, Set-PSReadLi…
Binary     2.0.3                 ThreadJob                           Desk      Start-ThreadJob

    Directory: C:\Program Files\WindowsPowerShell\Modules

ModuleType Version    PreRelease Name                                PSEdition ExportedCommands
---------- -------    ---------- ----                                --------- ----------------
Script     5.1.2                 Azure                               Desk      {Get-AzureAutomationCertificate, Get-Az…
Manifest   0.5.0                 Azure.AnalysisServices              Desk      {Add-AzureAnalysisServicesAccount, Rest…
Script     4.2.1                 Azure.Storage                       Desk      {Get-AzureStorageTable, New-AzureStorag…
Script     5.7.0                 AzureRM                             Desk
Script     0.6.6                 AzureRM.AnalysisServices            Desk      {Resume-AzureRmAnalysisServicesServer, …
Script     5.1.2                 AzureRM.ApiManagement               Desk      {Add-AzureRmApiManagementRegion, Get-Az…
Script     0.1.3                 AzureRM.ApplicationInsights         Desk      {Get-AzureRmApplicationInsights, New-Az…
Script     4.3.2                 AzureRM.Automation                  Desk      {Get-AzureRMAutomationHybridWorkerGroup…
Script     4.0.4                 AzureRM.Backup                      Desk      {Backup-AzureRmBackupItem, Enable-Azure…
Script     4.0.6                 AzureRM.Batch                       Desk      {Remove-AzureRmBatchAccount, Get-AzureR…
Script     0.14.1                AzureRM.Billing                     Desk      {Get-AzureRmBillingInvoice, Get-AzureRm…
Script     4.2.2                 AzureRM.Cdn                         Desk      {Get-AzureRmCdnProfile, Get-AzureRmCdnP…
Script     0.9.4                 AzureRM.CognitiveServices           Desk      {Get-AzureRmCognitiveServicesAccount, G…
Script     4.6.0                 AzureRM.Compute                     Desk      {Remove-AzureRmAvailabilitySet, Get-Azu…
Script     0.3.1                 AzureRM.Consumption                 Desk      Get-AzureRmConsumptionUsageDetail
Script     0.2.5                 AzureRM.ContainerInstance           Desk      {New-AzureRmContainerGroup, Get-AzureRm…
Script     1.0.4                 AzureRM.ContainerRegistry           Desk      {New-AzureRmContainerRegistry, Get-Azur…
Script     4.2.2                 AzureRM.DataFactories               Desk      {Remove-AzureRmDataFactory, Get-AzureRm…
Script     0.5.3                 AzureRM.DataFactoryV2               Desk      {Set-AzureRmDataFactoryV2, Update-Azure…
Script     4.2.3                 AzureRM.DataLakeAnalytics           Desk      {Get-AzureRmDataLakeAnalyticsDataSource…
Script     5.2.0                 AzureRM.DataLakeStore               Desk      {Get-AzureRmDataLakeStoreTrustedIdProvi…
Script     4.0.4                 AzureRM.DevTestLabs                 Desk      {Get-AzureRmDtlAllowedVMSizesPolicy, Ge…
Script     4.1.2                 AzureRM.Dns                         Desk      {Get-AzureRmDnsRecordSet, New-AzureRmDn…
Script     0.3.2                 AzureRM.EventGrid                   Desk      {New-AzureRmEventGridTopic, Get-AzureRm…
Script     0.6.3                 AzureRM.EventHub                    Desk      {New-AzureRmEventHubNamespace, Get-Azur…
Script     4.1.2                 AzureRM.HDInsight                   Desk      {Get-AzureRmHDInsightJob, New-AzureRmHD…
Script     4.0.4                 AzureRM.Insights                    Desk      {Get-AzureRmMetricDefinition, Get-Azure…
Script     3.1.2                 AzureRM.IotHub                      Desk      {Add-AzureRmIotHubKey, Get-AzureRmIotHu…
Script     4.3.0                 AzureRM.KeyVault                    Desk      {Add-AzureKeyVaultCertificate, Set-Azur…
Script     4.0.3                 AzureRM.LogicApp                    Desk      {Get-AzureRmIntegrationAccountAgreement…
Script     0.17.2                AzureRM.MachineLearning             Desk      {Move-AzureRmMlCommitmentAssociation, G…
Script     0.4.2                 AzureRM.MachineLearningCompute      Desk      {Get-AzureRmMlOpCluster, Get-AzureRmMlO…
Script     0.2.1                 AzureRM.MarketplaceOrdering         Desk      {Get-AzureRmMarketplaceTerms, Set-Azure…
Script     0.9.2                 AzureRM.Media                       Desk      {Sync-AzureRmMediaServiceStorageKeys, S…
Script     5.4.2                 AzureRM.Network                     Desk      {Add-AzureRmApplicationGatewayAuthentic…
Script     4.1.1                 AzureRM.NotificationHubs            Desk      {Get-AzureRmNotificationHub, Get-AzureR…
Script     4.3.2                 AzureRM.OperationalInsights         Desk      {New-AzureRmOperationalInsightsAzureAct…
Script     4.1.4                 AzureRM.PowerBIEmbedded             Desk      {Remove-AzureRmPowerBIWorkspaceCollecti…
Script     4.6.0                 AzureRM.Profile                     Desk      {Disable-AzureRmDataCollection, Disable…
Script     4.1.2                 AzureRM.RecoveryServices            Desk      {Get-AzureRmRecoveryServicesBackupPrope…
Script     4.1.2                 AzureRM.RecoveryServices.Backup     Desk      {Backup-AzureRmRecoveryServicesBackupIt…
Script     0.2.4                 AzureRM.RecoveryServices.SiteRecov… Desk      {Edit-AzureRmRecoveryServicesAsrRecover…
Script     4.1.2                 AzureRM.RedisCache                  Desk      {Remove-AzureRmRedisCachePatchSchedule,…
Script     0.3.3                 AzureRM.Relay                       Desk      {New-AzureRmRelayNamespace, Get-AzureRm…
Script     5.5.2                 AzureRM.Resources                   Desk      {Get-AzureRmProviderOperation, Remove-A…
Script     0.16.3                AzureRM.Scheduler                   Desk      {Disable-AzureRmSchedulerJobCollection,…
Script     4.1.2                 AzureRM.ServerManagement            Desk      {Invoke-AzureRmServerManagementPowerShe…
Script     0.6.4                 AzureRM.ServiceBus                  Desk      {New-AzureRmServiceBusNamespace, Get-Az…
Script     0.3.4                 AzureRM.ServiceFabric               Desk      {Add-AzureRmServiceFabricApplicationCer…
Script     5.0.6                 AzureRM.SiteRecovery                Desk      {Get-AzureRmSiteRecoveryFabric, New-Azu…
Script     4.4.0                 AzureRM.Sql                         Desk      {Get-AzureRmSqlDatabaseTransparentDataE…
Script     4.2.3                 AzureRM.Storage                     Desk      {Get-AzureRmStorageAccount, Get-AzureRm…
Script     4.0.4                 AzureRM.StreamAnalytics             Desk      {Get-AzureRmStreamAnalyticsFunction, Ge…
Script     4.0.1                 AzureRM.Tags                        Desk      {Remove-AzureRmTag, Get-AzureRmTag, New…
Script     4.0.3                 AzureRM.TrafficManager              Desk      {Disable-AzureRmTrafficManagerEndpoint,…
Script     4.0.2                 AzureRM.UsageAggregates             Desk      Get-UsageAggregates
Script     4.2.2                 AzureRM.Websites                    Desk      {Get-AzureRmAppServicePlan, Set-AzureRm…
Script     1.0.1                 Microsoft.PowerShell.Operation.Val… Desk      {Get-OperationValidation, Invoke-Operat…
Binary     1.0.0.1               PackageManagement                   Desk      {Find-Package, Get-Package, Get-Package…
Script     3.4.0                 Pester                              Desk      {Describe, Context, It, Should…}
Script     1.0.0.1               PowerShellGet                       Desk      {Install-Module, Find-Module, Save-Modu…
Script     2.0.0      beta2      PSReadline                          Desk      {Get-PSReadLineKeyHandler, Set-PSReadLi…

    Directory: C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules

ModuleType Version    PreRelease Name                                PSEdition ExportedCommands
---------- -------    ---------- ----                                --------- ----------------
Manifest   1.0.0.0               AppBackgroundTask                   Core,Desk {Disable-AppBackgroundTaskDiagnosticLog…
Manifest   2.0.1.0               Appx                                Core,Desk {Add-AppxPackage, Get-AppxPackage, Get-…
Manifest   1.0.0.0               BitLocker                           Core,Desk {Unlock-BitLocker, Suspend-BitLocker, R…
Manifest   2.0.0.0               BitsTransfer                        Core,Desk {Add-BitsFile, Complete-BitsTransfer, G…
Manifest   1.0                   ConfigDefender                      Core,Desk {Get-MpPreference, Set-MpPreference, Ad…
Manifest   1.0                   Defender                            Core,Desk {Get-MpPreference, Set-MpPreference, Ad…
Manifest   1.0.2.0               DeliveryOptimization                Core,Desk {Delete-DeliveryOptimizationCache, Set-…
Manifest   1.0.0.0               DirectAccessClientComponents        Core,Desk {Disable-DAManualEntryPointSelection, E…
Script     3.0                   Dism                                Core,Desk {Add-AppxProvisionedPackage, Add-Window…
Manifest   1.0.0.0               DnsClient                           Core,Desk {Resolve-DnsName, Clear-DnsClientCache,…
Manifest   1.0.0.0               EventTracingManagement              Core,Desk {Start-EtwTraceSession, New-EtwTraceSes…
Script     1.1.0.0               IISAdministration                   Core,Desk
Manifest   2.0.0.0               International                       Core,Desk {Get-WinDefaultInputMethodOverride, Set…
Manifest   1.0.0.0               Kds                                 Core,Desk {Add-KdsRootKey, Get-KdsRootKey, Test-K…
Manifest   3.0.0.0               Microsoft.PowerShell.Diagnostics    Core,Desk {Get-WinEvent, Get-Counter, Import-Coun…
Manifest   1.0.0.0               Microsoft.PowerShell.LocalAccounts  Core,Desk {Add-LocalGroupMember, Disable-LocalUse…
Manifest   3.1.0.0               Microsoft.PowerShell.Management     Core,Desk {Add-Content, Clear-Content, Clear-Item…
Manifest   1.0                   MMAgent                             Core,Desk {Disable-MMAgent, Enable-MMAgent, Set-M…
Manifest   2.0.0.0               NetAdapter                          Core,Desk {Disable-NetAdapter, Disable-NetAdapter…
Manifest   1.0.0.0               NetConnection                       Core,Desk {Get-NetConnectionProfile, Set-NetConne…
Manifest   1.0.0.0               NetEventPacketCapture               Core,Desk {New-NetEventSession, Remove-NetEventSe…
Manifest   2.0.0.0               NetLbfo                             Core,Desk {Add-NetLbfoTeamMember, Add-NetLbfoTeam…
Manifest   1.0.0.0               NetNat                              Core,Desk {Get-NetNat, Get-NetNatExternalAddress,…
Manifest   2.0.0.0               NetQos                              Core,Desk {Get-NetQosPolicy, Set-NetQosPolicy, Re…
Manifest   2.0.0.0               NetSecurity                         Core,Desk {Get-DAPolicyChange, New-NetIPsecAuthPr…
Manifest   1.0.0.0               NetSwitchTeam                       Core,Desk {New-NetSwitchTeam, Remove-NetSwitchTea…
Manifest   1.0.0.0               NetTCPIP                            Core,Desk {Get-NetIPAddress, Get-NetIPInterface, …
Manifest   1.0.0.0               NetworkConnectivityStatus           Core,Desk {Get-DAConnectionStatus, Get-NCSIPolicy…
Manifest   1.0.0.0               NetworkSwitchManager                Core,Desk {Disable-NetworkSwitchEthernetPort, Ena…
Manifest   1.0.0.0               NetworkTransition                   Core,Desk {Add-NetIPHttpsCertBinding, Disable-Net…
Manifest   1.0.0.0               PcsvDevice                          Core,Desk {Get-PcsvDevice, Start-PcsvDevice, Stop…
Manifest   1.0.0.0               PKI                                 Core,Desk {Add-CertificateEnrollmentPolicyServer,…
Manifest   1.0.0.0               PnpDevice                           Core,Desk {Get-PnpDevice, Get-PnpDeviceProperty, …
Manifest   1.1                   PrintManagement                     Core,Desk {Add-Printer, Add-PrinterDriver, Add-Pr…
Binary     1.0.11                ProcessMitigations                  Core,Desk {Get-ProcessMitigation, Set-ProcessMiti…
Script     3.0                   Provisioning                        Core,Desk {Install-ProvisioningPackage, Export-Pr…
Manifest   1.0.0.0               ScheduledTasks                      Core,Desk {Get-ScheduledTask, Set-ScheduledTask, …
Manifest   2.0.0.0               SecureBoot                          Core,Desk {Confirm-SecureBootUEFI, Set-SecureBoot…
Manifest   2.0.0.0               SmbShare                            Core,Desk {Get-SmbShare, Remove-SmbShare, Set-Smb…
Manifest   2.0.0.0               SmbWitness                          Core,Desk {Get-SmbWitnessClient, Move-SmbWitnessC…
Manifest   1.0.0.0               StartLayout                         Core,Desk {Export-StartLayout, Import-StartLayout…
Manifest   2.0.0.0               Storage                             Core,Desk {Add-InitiatorIdToMaskingSet, Add-Parti…
Manifest   2.0.0.0               TLS                                 Core,Desk {New-TlsSessionTicketKey, Enable-TlsSes…
Manifest   1.0.0.0               TroubleshootingPack                 Core,Desk {Get-TroubleshootingPack, Invoke-Troubl…
Manifest   2.0.0.0               TrustedPlatformModule               Core,Desk {Get-Tpm, Initialize-Tpm, Clear-Tpm, Un…
Manifest   2.0.0.0               VpnClient                           Core,Desk {Add-VpnConnection, Set-VpnConnection, …
Manifest   1.0.0.0               Wdac                                Core,Desk {Get-OdbcDriver, Set-OdbcDriver, Get-Od…
Manifest   2.0.0.0               Whea                                Core,Desk {Get-WheaMemoryPolicy, Set-WheaMemoryPo…
Manifest   1.0.0.0               WindowsDeveloperLicense             Core,Desk {Get-WindowsDeveloperLicense, Unregiste…
Script     1.0                   WindowsErrorReporting               Core,Desk {Enable-WindowsErrorReporting, Disable-…
Manifest   1.0.0.0               WindowsSearch                       Core,Desk {Get-WindowsSearchSetting, Set-WindowsS…
Manifest   1.0.0.0               WindowsUpdate                       Core,Desk Get-WindowsUpdateLog
Manifest   1.0.0.2               WindowsUpdateProvider               Core,Desk {Get-WUAVersion, Get-WULastInstallation…

    Directory: C:\Program Files (x86)\Microsoft SQL Server\150\Tools\PowerShell\Modules

ModuleType Version    PreRelease Name                                PSEdition ExportedCommands
---------- -------    ---------- ----                                --------- ----------------
Manifest   15.0                  SQLPS                               Desk
vamsidogiparthi commented 4 years ago

I am facing a similar issue. Not with Connect-AzAccount, but with all the other modules such as Get-AzureSubscription, Add-AzureAccount etc. Below are the list modules installed on my powershell and also the version of powershell i am running.

I tried to find a solution for this but couldn't able to do anything with it. I tried deleting all the modules and reinstall everything. But still it doesn't seem to work. When i use any az module command it says object not set.

PS C:\Users\vooo_> Get-AzureSubscription
Get-AzureSubscription: Object reference not set to an instance of an object.

PS C:\Users\vooo_> Add-AzureAccount
Add-AzureAccount: Object reference not set to an instance of an object.

PS C:\Users\vooo_> Get-AzureSubscription
Get-AzureSubscription: Object reference not set to an instance of an object.

Name                           Value
----                           -----
PSVersion                      7.0.2
PSEdition                      Core
GitCommitId                    7.0.2
OS                             Microsoft Windows 10.0.19041
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

    Directory: C:\Program Files\PowerShell\Modules

ModuleType Version    PreRelease Name                                PSEdition ExportedCommands
---------- -------    ---------- ----                                --------- ----------------
Script     4.3.0                 Az                                  Core,Desk
Script     1.9.0                 Az.Accounts                         Core,Desk {Disable-AzDataCollection, Disable-AzCo…
Script     1.1.1                 Az.Advisor                          Core,Desk {Get-AzAdvisorRecommendation, Enable-Az…
Script     1.1.2                 Az.Aks                              Core,Desk {Get-AzAks, New-AzAks, Remove-AzAks, Im…
Script     1.1.3                 Az.AnalysisServices                 Core,Desk {Resume-AzAnalysisServicesServer, Suspe…
Script     2.0.1                 Az.ApiManagement                    Core,Desk {Add-AzApiManagementApiToProduct, Add-A…
Script     1.1.0                 Az.ApplicationInsights              Core,Desk {Get-AzApplicationInsights, New-AzAppli…
Script     1.3.6                 Az.Automation                       Core,Desk {Get-AzAutomationHybridWorkerGroup, Rem…
Script     3.1.0                 Az.Batch                            Core,Desk {Remove-AzBatchAccount, Get-AzBatchAcco…
Script     1.0.3                 Az.Billing                          Core,Desk {Get-AzBillingInvoice, Get-AzBillingPer…
Script     1.4.3                 Az.Cdn                              Core,Desk {Get-AzCdnProfile, Get-AzCdnProfileSsoU…
Script     1.5.0                 Az.CognitiveServices                Core,Desk {Get-AzCognitiveServicesAccount, Get-Az…
Script     4.2.0                 Az.Compute                          Core,Desk {Remove-AzAvailabilitySet, Get-AzAvaila…
Script     1.0.3                 Az.ContainerInstance                Core,Desk {New-AzContainerGroup, Get-AzContainerG…
Script     1.1.1                 Az.ContainerRegistry                Core,Desk {New-AzContainerRegistry, Get-AzContain…
Script     1.1.0                 Az.DataBoxEdge                      Core,Desk {Get-AzDataBoxEdgeJob, Get-AzDataBoxEdg…
Script     1.8.2                 Az.DataFactory                      Core,Desk {Set-AzDataFactoryV2, Update-AzDataFact…
Script     1.0.2                 Az.DataLakeAnalytics                Core,Desk {Get-AzDataLakeAnalyticsDataSource, New…
Script     1.2.8                 Az.DataLakeStore                    Core,Desk {Get-AzDataLakeStoreTrustedIdProvider, …
Script     1.0.0                 Az.DataShare                        Core,Desk {New-AzDataShareAccount, Get-AzDataShar…
Script     1.1.0                 Az.DeploymentManager                Core,Desk {Get-AzDeploymentManagerArtifactSource,…
Script     1.0.0                 Az.DesktopVirtualization            Core,Desk {Disconnect-AzWvdUserSession, Get-AzWvd…
Script     1.0.2                 Az.DevTestLabs                      Core,Desk {Get-AzDtlAllowedVMSizesPolicy, Get-AzD…
Script     1.1.2                 Az.Dns                              Core,Desk {Get-AzDnsRecordSet, New-AzDnsRecordCon…
Script     1.2.3                 Az.EventGrid                        Core,Desk {New-AzEventGridTopic, Get-AzEventGridT…
Script     1.5.0                 Az.EventHub                         Core,Desk {New-AzEventHubNamespace, Get-AzEventHu…
Script     1.5.0                 Az.FrontDoor                        Core,Desk {New-AzFrontDoor, Get-AzFrontDoor, Set-…
Script     1.0.1                 Az.Functions                        Core,Desk {Get-AzFunctionApp, Get-AzFunctionAppAv…
Script     3.3.0                 Az.HDInsight                        Core,Desk {Get-AzHDInsightJob, New-AzHDInsightSqo…
Script     1.1.0                 Az.HealthcareApis                   Core,Desk {New-AzHealthcareApisService, Remove-Az…
Script     2.5.0                 Az.IotHub                           Core,Desk {Add-AzIotHubKey, Get-AzIotHubEventHubC…
Script     2.0.0                 Az.KeyVault                         Core,Desk {Add-AzKeyVaultCertificate, Update-AzKe…
Script     1.3.2                 Az.LogicApp                         Core,Desk {Get-AzIntegrationAccountAgreement, Get…
Script     1.1.3                 Az.MachineLearning                  Core,Desk {Move-AzMlCommitmentAssociation, Get-Az…
Script     1.0.0                 Az.Maintenance                      Core,Desk {Get-AzApplyUpdate, Get-AzConfiguration…
Script     1.0.2                 Az.ManagedServices                  Core,Desk {Get-AzManagedServicesAssignment, New-A…
Script     1.0.2                 Az.MarketplaceOrdering              Core,Desk {Get-AzMarketplaceTerms, Set-AzMarketpl…
Script     1.1.1                 Az.Media                            Core,Desk {Sync-AzMediaServiceStorageKey, Set-AzM…
Script     2.0.1                 Az.Monitor                          Core,Desk {Get-AzMetricDefinition, Get-AzMetric, …
Script     3.1.0                 Az.Network                          Core,Desk {Add-AzApplicationGatewayAuthentication…
Script     1.1.1                 Az.NotificationHubs                 Core,Desk {Get-AzNotificationHub, Get-AzNotificat…
Script     2.2.0                 Az.OperationalInsights              Core,Desk {New-AzOperationalInsightsAzureActivity…
Script     1.3.1                 Az.PolicyInsights                   Core,Desk {Get-AzPolicyEvent, Get-AzPolicyState, …
Script     1.1.2                 Az.PowerBIEmbedded                  Core,Desk {Remove-AzPowerBIWorkspaceCollection, G…
Script     1.0.3                 Az.PrivateDns                       Core,Desk {Get-AzPrivateDnsZone, Remove-AzPrivate…
Script     2.10.0                Az.RecoveryServices                 Core,Desk {Get-AzRecoveryServicesBackupProperty, …
Script     1.2.1                 Az.RedisCache                       Core,Desk {Remove-AzRedisCachePatchSchedule, New-…
Script     1.0.3                 Az.Relay                            Core,Desk {New-AzRelayNamespace, Get-AzRelayNames…
Script     2.2.0                 Az.Resources                        Core,Desk {Get-AzProviderOperation, Remove-AzRole…
Script     1.4.1                 Az.ServiceBus                       Core,Desk {New-AzServiceBusNamespace, Get-AzServi…
Script     2.1.0                 Az.ServiceFabric                    Core,Desk {Add-AzServiceFabricClientCertificate, …
Script     1.1.1                 Az.SignalR                          Core,Desk {New-AzSignalR, Get-AzSignalR, Get-AzSi…
Script     2.8.0                 Az.Sql                              Core,Desk {Get-AzSqlDatabaseTransparentDataEncryp…
Script     1.1.0                 Az.SqlVirtualMachine                Core,Desk {New-AzSqlVM, Get-AzSqlVM, Update-AzSql…
Script     2.2.0                 Az.Storage                          Core,Desk {Get-AzStorageAccount, Get-AzStorageAcc…
Script     1.2.3                 Az.StorageSync                      Core,Desk {Invoke-AzStorageSyncCompatibilityCheck…
Script     1.0.1                 Az.StreamAnalytics                  Core,Desk {Get-AzStreamAnalyticsFunction, Get-AzS…
Script     1.0.0                 Az.Support                          Core,Desk {Get-AzSupportService, Get-AzSupportPro…
Script     1.0.4                 Az.TrafficManager                   Core,Desk {Add-AzTrafficManagerCustomHeaderToEndp…
Script     1.10.0                Az.Websites                         Core,Desk {Get-AzAppServicePlan, Set-AzAppService…

    Directory: C:\program files\powershell\7\Modules

ModuleType Version    PreRelease Name                                PSEdition ExportedCommands
---------- -------    ---------- ----                                --------- ----------------
Manifest   7.0.0.0               CimCmdlets                          Core      {Get-CimAssociatedInstance, Get-CimClas…
Manifest   1.2.5                 Microsoft.PowerShell.Archive        Desk      {Compress-Archive, Expand-Archive}
Manifest   7.0.0.0               Microsoft.PowerShell.Diagnostics    Core      {Get-WinEvent, New-WinEvent, Get-Counte…
Manifest   7.0.0.0               Microsoft.PowerShell.Host           Core      {Start-Transcript, Stop-Transcript}
Manifest   7.0.0.0               Microsoft.PowerShell.Management     Core      {Add-Content, Clear-Content, Get-Clipbo…
Manifest   7.0.0.0               Microsoft.PowerShell.Security       Core      {Get-Acl, Set-Acl, Get-PfxCertificate, …
Manifest   7.0.0.0               Microsoft.PowerShell.Utility        Core      {Export-Alias, Get-Alias, Import-Alias,…
Manifest   7.0.0.0               Microsoft.WSMan.Management          Core      {Disable-WSManCredSSP, Enable-WSManCred…
Script     1.4.6                 PackageManagement                   Desk      {Find-Package, Get-Package, Get-Package…
Script     2.2.4                 PowerShellGet                       Desk      {Find-Command, Find-DSCResource, Find-M…
Script     2.0.5                 PSDesiredStateConfiguration         Core      {Configuration, New-DscChecksum, Get-Ds…
Script     7.0.0.0               PSDiagnostics                       Core      {Disable-PSTrace, Disable-PSWSManCombin…
Script     2.0.0                 PSReadLine                          Desk      {Get-PSReadLineKeyHandler, Set-PSReadLi…
Binary     2.0.3                 ThreadJob                           Desk      Start-ThreadJob

    Directory: C:\Program Files\WindowsPowerShell\Modules

ModuleType Version    PreRelease Name                                PSEdition ExportedCommands
---------- -------    ---------- ----                                --------- ----------------
Script     5.1.2                 Azure                               Desk      {Get-AzureAutomationCertificate, Get-Az…
Manifest   0.5.0                 Azure.AnalysisServices              Desk      {Add-AzureAnalysisServicesAccount, Rest…
Script     4.2.1                 Azure.Storage                       Desk      {Get-AzureStorageTable, New-AzureStorag…
Script     5.7.0                 AzureRM                             Desk
Script     0.6.6                 AzureRM.AnalysisServices            Desk      {Resume-AzureRmAnalysisServicesServer, …
Script     5.1.2                 AzureRM.ApiManagement               Desk      {Add-AzureRmApiManagementRegion, Get-Az…
Script     0.1.3                 AzureRM.ApplicationInsights         Desk      {Get-AzureRmApplicationInsights, New-Az…
Script     4.3.2                 AzureRM.Automation                  Desk      {Get-AzureRMAutomationHybridWorkerGroup…
Script     4.0.4                 AzureRM.Backup                      Desk      {Backup-AzureRmBackupItem, Enable-Azure…
Script     4.0.6                 AzureRM.Batch                       Desk      {Remove-AzureRmBatchAccount, Get-AzureR…
Script     0.14.1                AzureRM.Billing                     Desk      {Get-AzureRmBillingInvoice, Get-AzureRm…
Script     4.2.2                 AzureRM.Cdn                         Desk      {Get-AzureRmCdnProfile, Get-AzureRmCdnP…
Script     0.9.4                 AzureRM.CognitiveServices           Desk      {Get-AzureRmCognitiveServicesAccount, G…
Script     4.6.0                 AzureRM.Compute                     Desk      {Remove-AzureRmAvailabilitySet, Get-Azu…
Script     0.3.1                 AzureRM.Consumption                 Desk      Get-AzureRmConsumptionUsageDetail
Script     0.2.5                 AzureRM.ContainerInstance           Desk      {New-AzureRmContainerGroup, Get-AzureRm…
Script     1.0.4                 AzureRM.ContainerRegistry           Desk      {New-AzureRmContainerRegistry, Get-Azur…
Script     4.2.2                 AzureRM.DataFactories               Desk      {Remove-AzureRmDataFactory, Get-AzureRm…
Script     0.5.3                 AzureRM.DataFactoryV2               Desk      {Set-AzureRmDataFactoryV2, Update-Azure…
Script     4.2.3                 AzureRM.DataLakeAnalytics           Desk      {Get-AzureRmDataLakeAnalyticsDataSource…
Script     5.2.0                 AzureRM.DataLakeStore               Desk      {Get-AzureRmDataLakeStoreTrustedIdProvi…
Script     4.0.4                 AzureRM.DevTestLabs                 Desk      {Get-AzureRmDtlAllowedVMSizesPolicy, Ge…
Script     4.1.2                 AzureRM.Dns                         Desk      {Get-AzureRmDnsRecordSet, New-AzureRmDn…
Script     0.3.2                 AzureRM.EventGrid                   Desk      {New-AzureRmEventGridTopic, Get-AzureRm…
Script     0.6.3                 AzureRM.EventHub                    Desk      {New-AzureRmEventHubNamespace, Get-Azur…
Script     4.1.2                 AzureRM.HDInsight                   Desk      {Get-AzureRmHDInsightJob, New-AzureRmHD…
Script     4.0.4                 AzureRM.Insights                    Desk      {Get-AzureRmMetricDefinition, Get-Azure…
Script     3.1.2                 AzureRM.IotHub                      Desk      {Add-AzureRmIotHubKey, Get-AzureRmIotHu…
Script     4.3.0                 AzureRM.KeyVault                    Desk      {Add-AzureKeyVaultCertificate, Set-Azur…
Script     4.0.3                 AzureRM.LogicApp                    Desk      {Get-AzureRmIntegrationAccountAgreement…
Script     0.17.2                AzureRM.MachineLearning             Desk      {Move-AzureRmMlCommitmentAssociation, G…
Script     0.4.2                 AzureRM.MachineLearningCompute      Desk      {Get-AzureRmMlOpCluster, Get-AzureRmMlO…
Script     0.2.1                 AzureRM.MarketplaceOrdering         Desk      {Get-AzureRmMarketplaceTerms, Set-Azure…
Script     0.9.2                 AzureRM.Media                       Desk      {Sync-AzureRmMediaServiceStorageKeys, S…
Script     5.4.2                 AzureRM.Network                     Desk      {Add-AzureRmApplicationGatewayAuthentic…
Script     4.1.1                 AzureRM.NotificationHubs            Desk      {Get-AzureRmNotificationHub, Get-AzureR…
Script     4.3.2                 AzureRM.OperationalInsights         Desk      {New-AzureRmOperationalInsightsAzureAct…
Script     4.1.4                 AzureRM.PowerBIEmbedded             Desk      {Remove-AzureRmPowerBIWorkspaceCollecti…
Script     4.6.0                 AzureRM.Profile                     Desk      {Disable-AzureRmDataCollection, Disable…
Script     4.1.2                 AzureRM.RecoveryServices            Desk      {Get-AzureRmRecoveryServicesBackupPrope…
Script     4.1.2                 AzureRM.RecoveryServices.Backup     Desk      {Backup-AzureRmRecoveryServicesBackupIt…
Script     0.2.4                 AzureRM.RecoveryServices.SiteRecov… Desk      {Edit-AzureRmRecoveryServicesAsrRecover…
Script     4.1.2                 AzureRM.RedisCache                  Desk      {Remove-AzureRmRedisCachePatchSchedule,…
Script     0.3.3                 AzureRM.Relay                       Desk      {New-AzureRmRelayNamespace, Get-AzureRm…
Script     5.5.2                 AzureRM.Resources                   Desk      {Get-AzureRmProviderOperation, Remove-A…
Script     0.16.3                AzureRM.Scheduler                   Desk      {Disable-AzureRmSchedulerJobCollection,…
Script     4.1.2                 AzureRM.ServerManagement            Desk      {Invoke-AzureRmServerManagementPowerShe…
Script     0.6.4                 AzureRM.ServiceBus                  Desk      {New-AzureRmServiceBusNamespace, Get-Az…
Script     0.3.4                 AzureRM.ServiceFabric               Desk      {Add-AzureRmServiceFabricApplicationCer…
Script     5.0.6                 AzureRM.SiteRecovery                Desk      {Get-AzureRmSiteRecoveryFabric, New-Azu…
Script     4.4.0                 AzureRM.Sql                         Desk      {Get-AzureRmSqlDatabaseTransparentDataE…
Script     4.2.3                 AzureRM.Storage                     Desk      {Get-AzureRmStorageAccount, Get-AzureRm…
Script     4.0.4                 AzureRM.StreamAnalytics             Desk      {Get-AzureRmStreamAnalyticsFunction, Ge…
Script     4.0.1                 AzureRM.Tags                        Desk      {Remove-AzureRmTag, Get-AzureRmTag, New…
Script     4.0.3                 AzureRM.TrafficManager              Desk      {Disable-AzureRmTrafficManagerEndpoint,…
Script     4.0.2                 AzureRM.UsageAggregates             Desk      Get-UsageAggregates
Script     4.2.2                 AzureRM.Websites                    Desk      {Get-AzureRmAppServicePlan, Set-AzureRm…
Script     1.0.1                 Microsoft.PowerShell.Operation.Val… Desk      {Get-OperationValidation, Invoke-Operat…
Binary     1.0.0.1               PackageManagement                   Desk      {Find-Package, Get-Package, Get-Package…
Script     3.4.0                 Pester                              Desk      {Describe, Context, It, Should…}
Script     1.0.0.1               PowerShellGet                       Desk      {Install-Module, Find-Module, Save-Modu…
Script     2.0.0      beta2      PSReadline                          Desk      {Get-PSReadLineKeyHandler, Set-PSReadLi…

    Directory: C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules

ModuleType Version    PreRelease Name                                PSEdition ExportedCommands
---------- -------    ---------- ----                                --------- ----------------
Manifest   1.0.0.0               AppBackgroundTask                   Core,Desk {Disable-AppBackgroundTaskDiagnosticLog…
Manifest   2.0.1.0               Appx                                Core,Desk {Add-AppxPackage, Get-AppxPackage, Get-…
Manifest   1.0.0.0               BitLocker                           Core,Desk {Unlock-BitLocker, Suspend-BitLocker, R…
Manifest   2.0.0.0               BitsTransfer                        Core,Desk {Add-BitsFile, Complete-BitsTransfer, G…
Manifest   1.0                   ConfigDefender                      Core,Desk {Get-MpPreference, Set-MpPreference, Ad…
Manifest   1.0                   Defender                            Core,Desk {Get-MpPreference, Set-MpPreference, Ad…
Manifest   1.0.2.0               DeliveryOptimization                Core,Desk {Delete-DeliveryOptimizationCache, Set-…
Manifest   1.0.0.0               DirectAccessClientComponents        Core,Desk {Disable-DAManualEntryPointSelection, E…
Script     3.0                   Dism                                Core,Desk {Add-AppxProvisionedPackage, Add-Window…
Manifest   1.0.0.0               DnsClient                           Core,Desk {Resolve-DnsName, Clear-DnsClientCache,…
Manifest   1.0.0.0               EventTracingManagement              Core,Desk {Start-EtwTraceSession, New-EtwTraceSes…
Script     1.1.0.0               IISAdministration                   Core,Desk
Manifest   2.0.0.0               International                       Core,Desk {Get-WinDefaultInputMethodOverride, Set…
Manifest   1.0.0.0               Kds                                 Core,Desk {Add-KdsRootKey, Get-KdsRootKey, Test-K…
Manifest   3.0.0.0               Microsoft.PowerShell.Diagnostics    Core,Desk {Get-WinEvent, Get-Counter, Import-Coun…
Manifest   1.0.0.0               Microsoft.PowerShell.LocalAccounts  Core,Desk {Add-LocalGroupMember, Disable-LocalUse…
Manifest   3.1.0.0               Microsoft.PowerShell.Management     Core,Desk {Add-Content, Clear-Content, Clear-Item…
Manifest   1.0                   MMAgent                             Core,Desk {Disable-MMAgent, Enable-MMAgent, Set-M…
Manifest   2.0.0.0               NetAdapter                          Core,Desk {Disable-NetAdapter, Disable-NetAdapter…
Manifest   1.0.0.0               NetConnection                       Core,Desk {Get-NetConnectionProfile, Set-NetConne…
Manifest   1.0.0.0               NetEventPacketCapture               Core,Desk {New-NetEventSession, Remove-NetEventSe…
Manifest   2.0.0.0               NetLbfo                             Core,Desk {Add-NetLbfoTeamMember, Add-NetLbfoTeam…
Manifest   1.0.0.0               NetNat                              Core,Desk {Get-NetNat, Get-NetNatExternalAddress,…
Manifest   2.0.0.0               NetQos                              Core,Desk {Get-NetQosPolicy, Set-NetQosPolicy, Re…
Manifest   2.0.0.0               NetSecurity                         Core,Desk {Get-DAPolicyChange, New-NetIPsecAuthPr…
Manifest   1.0.0.0               NetSwitchTeam                       Core,Desk {New-NetSwitchTeam, Remove-NetSwitchTea…
Manifest   1.0.0.0               NetTCPIP                            Core,Desk {Get-NetIPAddress, Get-NetIPInterface, …
Manifest   1.0.0.0               NetworkConnectivityStatus           Core,Desk {Get-DAConnectionStatus, Get-NCSIPolicy…
Manifest   1.0.0.0               NetworkSwitchManager                Core,Desk {Disable-NetworkSwitchEthernetPort, Ena…
Manifest   1.0.0.0               NetworkTransition                   Core,Desk {Add-NetIPHttpsCertBinding, Disable-Net…
Manifest   1.0.0.0               PcsvDevice                          Core,Desk {Get-PcsvDevice, Start-PcsvDevice, Stop…
Manifest   1.0.0.0               PKI                                 Core,Desk {Add-CertificateEnrollmentPolicyServer,…
Manifest   1.0.0.0               PnpDevice                           Core,Desk {Get-PnpDevice, Get-PnpDeviceProperty, …
Manifest   1.1                   PrintManagement                     Core,Desk {Add-Printer, Add-PrinterDriver, Add-Pr…
Binary     1.0.11                ProcessMitigations                  Core,Desk {Get-ProcessMitigation, Set-ProcessMiti…
Script     3.0                   Provisioning                        Core,Desk {Install-ProvisioningPackage, Export-Pr…
Manifest   1.0.0.0               ScheduledTasks                      Core,Desk {Get-ScheduledTask, Set-ScheduledTask, …
Manifest   2.0.0.0               SecureBoot                          Core,Desk {Confirm-SecureBootUEFI, Set-SecureBoot…
Manifest   2.0.0.0               SmbShare                            Core,Desk {Get-SmbShare, Remove-SmbShare, Set-Smb…
Manifest   2.0.0.0               SmbWitness                          Core,Desk {Get-SmbWitnessClient, Move-SmbWitnessC…
Manifest   1.0.0.0               StartLayout                         Core,Desk {Export-StartLayout, Import-StartLayout…
Manifest   2.0.0.0               Storage                             Core,Desk {Add-InitiatorIdToMaskingSet, Add-Parti…
Manifest   2.0.0.0               TLS                                 Core,Desk {New-TlsSessionTicketKey, Enable-TlsSes…
Manifest   1.0.0.0               TroubleshootingPack                 Core,Desk {Get-TroubleshootingPack, Invoke-Troubl…
Manifest   2.0.0.0               TrustedPlatformModule               Core,Desk {Get-Tpm, Initialize-Tpm, Clear-Tpm, Un…
Manifest   2.0.0.0               VpnClient                           Core,Desk {Add-VpnConnection, Set-VpnConnection, …
Manifest   1.0.0.0               Wdac                                Core,Desk {Get-OdbcDriver, Set-OdbcDriver, Get-Od…
Manifest   2.0.0.0               Whea                                Core,Desk {Get-WheaMemoryPolicy, Set-WheaMemoryPo…
Manifest   1.0.0.0               WindowsDeveloperLicense             Core,Desk {Get-WindowsDeveloperLicense, Unregiste…
Script     1.0                   WindowsErrorReporting               Core,Desk {Enable-WindowsErrorReporting, Disable-…
Manifest   1.0.0.0               WindowsSearch                       Core,Desk {Get-WindowsSearchSetting, Set-WindowsS…
Manifest   1.0.0.0               WindowsUpdate                       Core,Desk Get-WindowsUpdateLog
Manifest   1.0.0.2               WindowsUpdateProvider               Core,Desk {Get-WUAVersion, Get-WULastInstallation…

    Directory: C:\Program Files (x86)\Microsoft SQL Server\150\Tools\PowerShell\Modules

ModuleType Version    PreRelease Name                                PSEdition ExportedCommands
---------- -------    ---------- ----                                --------- ----------------
Manifest   15.0                  SQLPS                               Desk

The issue i have been facing disappeared when I

  1. Downgraded my Powershell version from 7.0.2 to 7.0.1.
  2. Removed my Az accounts modules folder completely.
  3. Re-installed the az module with this command Install-Module -Name Az -AllowClobber -Scope AllUsers.
  4. Running Connect-AzAccount.

So, the issue seems to be something with powershell v 7.0.2

awsles commented 4 years ago

When is this going to be fixed?

WORKAROUND: Use Az.Accounts v1.7.0

dingmeng-xue commented 4 years ago

@lesterw1 , do you have reproduce steps? Please ensure tenant you are connecting contains subscription. and ensure you have Az modules but without AzureRM or Azure.