diff --git a/sdks/auth_aad/src/token_credentials/cli_credentials.rs b/sdks/auth_aad/src/token_credentials/cli_credentials.rs index 4fadcf173d..1aba7d4c1d 100644 --- a/sdks/auth_aad/src/token_credentials/cli_credentials.rs +++ b/sdks/auth_aad/src/token_credentials/cli_credentials.rs @@ -39,16 +39,33 @@ pub struct AzureCliCredential; #[async_trait::async_trait] impl TokenCredential for AzureCliCredential { async fn get_token(&self, resource: &str) -> Result { - let az_command = Command::new("az") - .args(&[ - "account", - "get-access-token", - "--output", - "json", - "--resource", - resource, - ]) - .output(); + let az_command = if cfg!(target_os = "windows") { + // on window az is a cmd and it should be called like this + // see https://doc.rust-lang.org/nightly/std/process/struct.Command.html + Command::new("cmd") + .args(&[ + "/C", + "az", + "account", + "get-access-token", + "--output", + "json", + "--resource", + resource, + ]) + .output() + } else { + Command::new("az") + .args(&[ + "account", + "get-access-token", + "--output", + "json", + "--resource", + resource, + ]) + .output() + }; let res = match az_command { Ok(az_output) => {