How to Upload Blob to Azure Storage Account using PowerShell

Jul 6 2022 9:24 AM

Based on the script in the link below:

How to Upload Blob Contents in an Azure Storage Account using PowerShell (

can i connect with Service principal  as below ?? instead of just Connect-AzAccount  

## Input Parameters  

# automation scripts stay secure BY USING by using Service principals which are non-interactive Azure accounts
# Use the application ID as the username, and the secret as password

    $credentials = Get-Credential
    Connect-AzAccount -ServicePrincipal -Credential $credentials -Tenant <tenant ID>
## Function to upload blob contents  
    Function UploadBlobContent  
            Write-Host -ForegroundColor Green "Uploading blob content.."  
        ## Get the storage account  
             $storageAcc=Get-AzStorageAccount -ResourceGroupName $resourceGroupName -Name $storageAccName      
         ## Get the storage account context  
         ## Upload a file  
             Set-AzStorageBlobContent -Container $storageContainerName -File $filePath -Blob $fileName -Context $ctx -Force      
## Disconnect from Azure Account  

Answers (1)