我尝试使用copy-item将wwwroot中的文件复制到blob无法正常工作。能否将可用的任何脚本发送给我。 这将对我有很大的帮助。 我是PowerShell的新手
答案 0 :(得分:0)
根据我的经验,将某些文件和目录复制到Azure Blob存储的简单方法是使用AzCopy 这是我实现将Azure WebApp的D:\ home \ site下的资源复制到Blob存储的步骤。
azcopy / Source:D:\ home \ site \ wwwroot / Dest:“您的容器网址” / Destkey:“您的存储密钥” / s
有关更多详细信息,请参阅https://docs.microsoft.com/en-us/azure/storage/common/storage-use-azcopy?toc=%2fazure%2fstorage%2fblobs%2ftoc.json
更新
$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
}
}