Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] AzurePowerShellCredential cannot find Powershell #28030

Closed
yunxzhan opened this issue Apr 6, 2022 · 2 comments · Fixed by #30214
Closed

[BUG] AzurePowerShellCredential cannot find Powershell #28030

yunxzhan opened this issue Apr 6, 2022 · 2 comments · Fixed by #30214
Assignees
Labels
Azure.Identity Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that

Comments

@yunxzhan
Copy link

yunxzhan commented Apr 6, 2022

Library name and version

Azure.Identity 1.6.0

Describe the bug

Using AzurePowerShellCredential to get token while getting error saying I have not installed the Powershell.

CredentialUnavailableException
PowerShell is not installed.

Having powershell 5.1 installed and azure powershell installed in machine.

PS C:\Users\YUNXZHAN> $host.Version

Major  Minor  Build  Revision
-----  -----  -----  --------
5      1      22000  593

Expected behavior

N/A

Actual behavior

N/A

Reproduction Steps

AzurePowerShellCredential environmentCredential = new AzurePowerShellCredential();
accessToken = await environmentCredential.GetTokenAsync(new TokenRequestContext(new string[] { authority + "/.default" }), cancellationToken).ConfigureAwait(false);

Environment

target .netstandard 2.0

@ghost ghost added needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. customer-reported Issues that are reported by GitHub users external to the Azure organization. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Apr 6, 2022
@azure-sdk azure-sdk added Azure.Identity Client This issue points to a problem in the data-plane of the library. needs-team-triage Workflow: This issue needs the team to triage. labels Apr 6, 2022
@ghost ghost removed the needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. label Apr 6, 2022
@jsquire jsquire added needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team and removed needs-team-triage Workflow: This issue needs the team to triage. labels Apr 6, 2022
@jsquire
Copy link
Member

jsquire commented Apr 6, 2022

Thank you for your feedback. Tagging and routing to the team member best able to assist.

@emmanuelbenitez
Copy link

I have the same issue. I debug the code and i found more details about the bug.

The method GetTokenImplAsync (code here) of the class Azure.Identity.AzurePowerShellCredential try to execute the script based on the PowerShell Core. If the executable pwsh does not exist or is not found, the script is executed based on the PowerShell Framework.

The bug is coming from the expected exception when PowerShell Core is not installed.

Expected exception:

try
{
    // Unrelevant code
}
catch (Win32Exception ex) when (ex.NativeErrorCode == ERROR_FILE_NOT_FOUND && RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
    UseLegacyPowerShell = true;
    try
    {
        AccessToken token = await RequestAzurePowerShellAccessTokenAsync(async, requestContext, cancellationToken).ConfigureAwait(false);

        if (_logAccountDetails)
        {
            AzureIdentityEventSource.Singleton.AuthenticatedAccountDetails(null, _tenantId, null, null);
        }

        return scope.Succeeded(token);
    }
    catch (Exception e)
    {
        throw scope.FailWrapAndThrow(e);
    }
}

Actual Exception:

'pwsh' is not recognized as an internal or external command, operable program or batch file.

   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() in f:\dd\ndp\clr\src\BCL\system\runtime\exceptionservices\exceptionservicescommon.cs:line 133
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) in f:\dd\ndp\clr\src\BCL\system\runtime\compilerservices\TaskAwaiter.cs:line 156
   at Azure.Identity.ProcessRunner.Run() in /_/sdk/identity/Azure.Identity/src/ProcessRunner.cs:line 65
   at Azure.Identity.AzurePowerShellCredential.<RequestAzurePowerShellAccessTokenAsync>d__26.MoveNext() in /_/sdk/identity/Azure.Identity/src/AzurePowerShellCredential.cs:line 140

As workaround, the installation of PowerShell core fix the issue.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Azure.Identity Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants