使用Azure自动化帐户,跨存储将文件从一个文件共享复制到另一个文件共享

时间:2020-05-10 09:19:03

标签: azure powershell azure-storage azure-automation fileshare

我正在尝试将一个文件(x)从存储(z)的文件共享(y)复制到存储(b)的文件共享(a)。

$StorageAccountName = "z"
$StorageAccessKey = 
"md226fZvTKPKaCd9TxDGPn4mitCPfvBvgzElwoqIgpbf2Pe09GKKfNJlMcK2EXXqRLqOrhBslybaE1Cpz2BcPg=="
$context1=New-AzureStorageContext $StorageAccountName $StorageAccessKey

$DestStorageAccountName = "b"
$DestStorageAccessKey = "xZjU0r5g5fU+/ieAbwc22OmVtFY5BJdQuF8OZsFd7hGHYLzQFGg9ZCpsVnQi5u6Wi/nigb8jdupUGo0YaXBphg=="
$destcontext1=New-AzureStorageContext $DestStorageAccountName $DestStorageAccessKey
$SrcPath = "https://z.file.core.windows.net/y/x"
$SrcShare = "y"
$DestPath = "https://b.file.core.windows.net/a"
$DestShare = "a"
Start-AzureStorageFileCopy -SrcFilePath $SrcPath -SrcShareName $SrcShare -DestShareName $DestShare - 
DestFilePath $DestPath -Context $context1 -DestContext $destcontext1 -Force

它给我以下错误:

Start-AzStorageFileCopy:给定的路径/前缀'https:'不是文件或目录的有效名称,或者与Microsoft Azure File Service REST API的要求匹配。

预先感谢!

1 个答案:

答案 0 :(得分:2)

请更改源路径和目标路径。在您的特定情况下,它们应该代表相对于共享的路径。

$StorageAccountName = "z"
$StorageAccessKey = 
"md226fZvTKPKaCd9TxDGPn4mitCPfvBvgzElwoqIgpbf2Pe09GKKfNJlMcK2EXXqRLqOrhBslybaE1Cpz2BcPg=="
$context1=New-AzureStorageContext $StorageAccountName $StorageAccessKey

$DestStorageAccountName = "b"
$DestStorageAccessKey = "xZjU0r5g5fU+/ieAbwc22OmVtFY5BJdQuF8OZsFd7hGHYLzQFGg9ZCpsVnQi5u6Wi/nigb8jdupUGo0YaXBphg=="
$destcontext1=New-AzureStorageContext $DestStorageAccountName $DestStorageAccessKey
$SrcPath = "test.txt" #assuming the name of the source file is "test.txt"
$SrcShare = "y"
$DestPath = "test.txt" #assuming you want to copy the file and keep the same name
$DestShare = "a"
Start-AzureStorageFileCopy -SrcFilePath $SrcPath -SrcShareName $SrcShare -DestShareName $DestShare - 
DestFilePath $DestPath -Context $context1 -DestContext $destcontext1 -Force

从文档link

-SrcFilePath 指定相对于源目录或源共享的源文件的路径。

-DestFilePath 指定目标文件相对于目标共享的路径。