How do I connect to Azure Blob with Powershell unattended

Christopher Jack 0 Reputation points
2023-02-08T09:18:32.2733333+00:00

Hi,

When Trying to use the below , I get the following error, how can I loging using MFA unattended into azure

You must use multi-factor authentication to access tenant bladebla please rerun 'Connect-AzAccount' with additional parameter '-TenantId bladebla'.

$username = "******@accaglobal.com"
$password= "password!"
$SecurePassword = ConvertTo-SecureString $password -AsPlainText -Force
$credentials = New-Object System.Management.Automation.PSCredential($username, $SecurePassword)
Login-AzAccount -Credential $credentials -TenantId bladebla
Azure Blob Storage
Azure Blob Storage
An Azure service that stores unstructured data in the cloud as blobs.
3,192 questions
Windows for business Windows Server User experience PowerShell
{count} votes

1 answer

Sort by: Most helpful
  1. SaiKishor-MSFT 17,336 Reputation points
    2023-02-08T20:09:04.47+00:00

    @Christopher Jack To connect to Azure Blob with PowerShell unattended using MFA, you will need to use the 'Connect-AzAccount' command with the '-ServicePrincipal' and '-Tenant' parameters, as well as the '-UseDeviceAuthentication' parameter. The '-UseDeviceAuthentication' parameter allows you to authenticate with MFA using a device that has been registered with Azure Active Directory.

    You will also need to create a service principal in Azure Active Directory and assign it the appropriate permissions to access the blob storage. Once you have the service principal's client ID and client secret, you can use them to authenticate with the 'Connect-AzAccount' command.

    Here is an example of how to connect to Azure Blob with PowerShell unattended using MFA:

    $clientId = "your-client-id"
    $clientSecret = "your-client-secret"
    $tenantId = "your-tenant-id"
    Connect-AzAccount -ServicePrincipal -Tenant $tenantId -ApplicationId $clientId -Password $clientSecret -UseDeviceAuthentication
    

    You will be prompted to enter the verification code that is sent to your registered device. Once you have entered the code, you will be authenticated and able to access the blob storage.

    Please note that you will need to have the Azure MFA app installed on your device and have registered it with Azure Active Directory.

    Hope this helps. Please let us know if you have any more questions and we will be glad to assist you further. Thank you!

    Remember:

    Please accept an answer if correct. Original posters help the community find answers faster by identifying the correct answer. Here is how.

    Want a reminder to come back and check responses? Here is how to subscribe to a notification.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.