Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法将AzureStorageContext转换为IStorageContext_Azure_Powershell_Azure Storage_Azure Storage Blobs - Fatal编程技术网

无法将AzureStorageContext转换为IStorageContext

无法将AzureStorageContext转换为IStorageContext,azure,powershell,azure-storage,azure-storage-blobs,Azure,Powershell,Azure Storage,Azure Storage Blobs,我想将文件从Azure Blob存储容器复制到Azure文件共享(在同一Azure存储帐户中) 使用Start-AzureStorageFileCopy或New-AzureStorageDirectory时,上下文参数出现错误: Start-AzureStorageFileCopy:无法绑定参数“上下文”。不能 转换 “Microsoft.WindowsAzure.Commands.Storage.AzureStorageContext”的值 键入“Microsoft.WindowsAzure.

我想将文件从Azure Blob存储容器复制到Azure文件共享(在同一Azure存储帐户中)

使用Start-AzureStorageFileCopy或New-AzureStorageDirectory时,上下文参数出现错误:

Start-AzureStorageFileCopy:无法绑定参数“上下文”。不能 转换 “Microsoft.WindowsAzure.Commands.Storage.AzureStorageContext”的值 键入“Microsoft.WindowsAzure.Commands.Storage.AzureStorageContext”以 类型 “Microsoft.Azure.Commands.Common.Authentication.Abstractions.IStorageContext”

我尝试在上下文参数之后添加.Context,它显示的是IStorageContext而不是AzureStorageContext,但得到了相同的错误


奇怪的是,3周前它还可以正常工作,现在我发现了这个错误。不确定同时发生了什么变化

您不能将新的
Az
命令与旧的
AzureRm
命令混合使用。您应该注意,不仅是
Az.Storage
Azure.Storage
模块,还有其他模块,它们给出了不同的错误。我已经多次遇到这种情况

因此,在您的情况下,请重新打开新的powershell会话,使用和,而不是
启动AzureStorageFileCopy
新建AzureStorageDirectory


或者,如果您不想更改脚本,可以重新打开一个新的powershell会话,在运行所有命令之前运行,它也会工作。

混合使用
Az
Azure时,这似乎是一个已知问题。存储
命令:-坚持使用其中一个命令,看起来您是对的!谢谢。@MathiasR.Jessen因为这个问题已经解决了,你能发布答案吗?它可能会帮助更多有类似问题的人。
$StorageAccountName = "myStorageAccount"
$StorageAccountKey = "FAKEbkasdw504jfja0jgldheeeffl03659d0ch259fv=="
$ContainerName = "myContainerName"
$ShareName = "myShareName"


Write-Output "Start moving folder content $($ContainerName) from storageaccount $($StorageAccountName) to file share $($ShareName)"

# Get 'context' of the source container
$StorageContext = New-AzStorageContext  -StorageAccountName $StorageAccountName `
                                        -StorageAccountKey $StorageAccountKey


# Loop through all blobs
$blobs = Get-AzStorageBlob -Container $ContainerName -Context $StorageContext
foreach ($blob in $blobs)
{
    # Switch slashes because fileshare expects \ instead /
    $FilePath = $blob.name -replace '/','\'

    # Get folderpath to create new folders
    $FolderPath = Split-Path -Path $FilePath

    # If folder was found (not the case for files in the rooth) create it on the share
    # Todo: check if it exists
    if ($FolderPath.Length -gt 0)
    {
        # Create folder
        Write-Output "Create folder $($FolderPath) in fileshare"
        New-AzureStorageDirectory   -ShareName $ShareName            `
                                    -Path $FolderPath                `
                                    -Context $StorageContext.Context `
                                    -ErrorAction SilentlyContinue #Todo check if folder already exits
    }

    # Copy file from blob storage container to fileshare
    Write-Output "Copy file $($blob.name) to fileshare"
    Start-AzureStorageFileCopy  -SrcContainerName $ContainerName    `
                                -SrcBlobName $blob.name             `
                                -DestShareName $ShareName           `
                                -DestFilePath $FilePath             `
                                -Context $StorageContext.Context    `
                                -DestContext $StorageContext.Context     


    # Delete file from blob storage container
    Write-Output "Remove blob $($blob.name) from blob container"
    Remove-AzStorageBlob -Context $StorageContext -Blob $blob.name -Container $ContainerName
}