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
Asked
Active
Viewed 894 times
1 Answers
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.
- 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.
- Use command to copy file
azcopy /Source:D:\home\site\wwwroot /Dest:"your container url" /Destkey:"your storage key" /s
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
-
Thanks for the answer Farid, but i need to write the script so that i can use in VSTS Task as backup whenever new code deploys – S P May 17 '19 at 10:44
-
I have an update to tell you how to use Azure PowerShell to upload file to Azure storage. – Md Farid Uddin Kiron May 20 '19 at 05:25
-
farid itis not allowing me to copy from wwwroot folder(Kudu) – S P May 21 '19 at 09:18