@@ -159,7 +159,7 @@ private async ValueTask<AccessToken> RequestAzurePowerShellAccessTokenAsync(bool
159
159
try
160
160
{
161
161
output = async ? await processRunner . RunAsync ( ) . ConfigureAwait ( false ) : processRunner . Run ( ) ;
162
- CheckForErrors ( output ) ;
162
+ CheckForErrors ( output , processRunner . ExitCode ) ;
163
163
ValidateResult ( output ) ;
164
164
}
165
165
catch ( OperationCanceledException ) when ( ! cancellationToken . IsCancellationRequested )
@@ -168,7 +168,7 @@ private async ValueTask<AccessToken> RequestAzurePowerShellAccessTokenAsync(bool
168
168
}
169
169
catch ( InvalidOperationException exception )
170
170
{
171
- CheckForErrors ( exception . Message ) ;
171
+ CheckForErrors ( exception . Message , processRunner . ExitCode ) ;
172
172
if ( _isChainedCredential )
173
173
{
174
174
throw new CredentialUnavailableException ( $ "{ AzurePowerShellFailedError } { exception . Message } ") ;
@@ -181,9 +181,10 @@ private async ValueTask<AccessToken> RequestAzurePowerShellAccessTokenAsync(bool
181
181
return DeserializeOutput ( output ) ;
182
182
}
183
183
184
- private static void CheckForErrors ( string output )
184
+ private static void CheckForErrors ( string output , int exitCode )
185
185
{
186
- bool noPowerShell = ( output . IndexOf ( "not found" , StringComparison . OrdinalIgnoreCase ) != - 1 ||
186
+ int notFoundExitCode = RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) ? 9009 : 127 ;
187
+ bool noPowerShell = ( exitCode == notFoundExitCode || output . IndexOf ( "not found" , StringComparison . OrdinalIgnoreCase ) != - 1 ||
187
188
output . IndexOf ( "is not recognized" , StringComparison . OrdinalIgnoreCase ) != - 1 ) &&
188
189
// If the error contains AADSTS, this should be treated as a general error to be bubbled to the user
189
190
output . IndexOf ( "AADSTS" , StringComparison . OrdinalIgnoreCase ) == - 1 ;
@@ -264,7 +265,7 @@ private void GetFileNameAndArguments(string resource, string tenantId, out strin
264
265
if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) )
265
266
{
266
267
fileName = Path . Combine ( DefaultWorkingDirWindows , "cmd.exe" ) ;
267
- argument = $ "/d /c \" { powershellExe } \" { commandBase64 } \" \" ";
268
+ argument = $ "/d /c \" { powershellExe } \" { commandBase64 } \" \" & exit ";
268
269
}
269
270
else
270
271
{
0 commit comments