1

I tried copying files in wwwroot to blob using copy-item it's not working.could you please send me the any script available with you. It would be a great help for me. I'm new to powershell

S P
  • 23
  • 1
  • 5

1 Answers1

1

Per my experience, the simple way to copy some files and directories to Azure Blob Storage is to use AzCopy Here are my steps to realize for copying resources under D:\home\site of Azure WebApp to Blob Storage.

  1. First, I installed AzCopy v8 on my local Windows machine, and upload the AzCopy directory under C:\Program Files (x86)\Microsoft SDKs\Azure into Kudo Console path D:\home\site, as the figure below.

enter image description here

  1. Use command to copy file

azcopy /Source:D:\home\site\wwwroot /Dest:"your container url" /Destkey:"your storage key" /s

enter image description here For more details, please refer to https://learn.microsoft.com/en-us/azure/storage/common/storage-use-azcopy?toc=%2fazure%2fstorage%2fblobs%2ftoc.json

Update

$Username = ""
$password = ""
$secpasswd = ConvertTo-SecureString $password -AsPlainText -Force
$mycreds = New-Object System.Management.Automation.PSCredential ($name, $secpasswd)
Add-AzureRmAccount -Credential $mycreds
$ResourceGroupName=""
$AccountNmae=""
$ContainerName=""
$account =Get-AzureRmStorageAccount -ResourceGroupName $ResourceGroupName -Name $AccountNmae

$container=Get-AzureStorageContainer -Name $ContainerName -Context $account.Context

$sourceFileRootDirectory = ""

if ($container) {
        $filesToUpload = Get-ChildItem $sourceFileRootDirectory -Recurse

        foreach ($x in $filesToUpload) {
            $targetPath = ($x.fullname.Substring($sourceFileRootDirectory.Length + 1)).Replace("\", "/")

            Write-Verbose "Uploading $("\" + $x.fullname.Substring($sourceFileRootDirectory.Length + 1)) to $($container.CloudBlobContainer.Uri.AbsoluteUri + "/" + $targetPath)"
            Set-AzureStorageBlobContent -File $x.fullname -Container $container.Name -Blob $targetPath -Context $account.Context -Force | Out-Null
        }
    }
Md Farid Uddin Kiron
  • 16,817
  • 3
  • 17
  • 43