'The term 'AzCopy' is not recognized as a name of a cmdlet, function, script file

I need to copy tables from table storage into a different storage account. When attempting to execute AzCopy I'm getting the following exception:

The term 'AzCopy' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

I'm connected to the terminal from the portal, and have a powershell prompt:

enter image description here

The issue seems to be with this line:

    AzCopy /Source:$SrcTableUrl `
                      /Dest:$DstBlobUrl/$TableName `
                      /SourceKey:$SrcAccessKey `
                      /Destkey:$DstAccessKey

How do we run AzCopy command in the terminal in the Azure portal?

Here's the full code powershell script that I'm attempting to execute:

# This simple PowerShell script will copy one or more Azure storage table from one location into another azure storage table
#
# Dependencies :
#   https://docs.microsoft.com/en-us/azure/storage/common/storage-use-azcopy
#   https://docs.microsoft.com/en-us/powershell/azure/overview?view=azps-1.6.0
#
# Usage :
#        Copy-AzureStorageTable -SrcStorageName "" -SrcAccessKey "" -DstStorageName "" -DstAccessKey "" -IncludeTable All  
#        Copy-AzureStorageTable -SrcStorageName "" -SrcAccessKey "" -DstStorageName "" -DstAccessKey "" -IncludeTable Table1,Table2,Table3  

function Copy-AzureStorageTable
{
    param
    (
        [parameter(Mandatory=$true)]
        [String]
        $SrcStorageName,

        [parameter(Mandatory=$true)]
        [String]
        $SrcAccessKey,

        [parameter(Mandatory=$true)]
        [String]
        $DstStorageName,

        [parameter(Mandatory=$true)]
        [String]
        $DstAccessKey,

        [parameter(Mandatory=$true)]
        [String[]]
        $IncludeTable
    )

    # Check if logged in
    Azure-Login

    # Source Account Storage Parameters
    $SrcContext = New-AzureStorageContext -StorageAccountName $SrcStorageName -StorageAccountKey $SrcAccessKey
    $SrcBaseUrl = "https://" + $SrcStorageName + ".table.core.windows.net/"

    # Destination Account Storage Parameters
    $DstContext = New-AzureStorageContext -StorageAccountName $DstStorageName -StorageAccountKey $DstAccessKey
    $DstTempContainer = "temptable"
    $DstBlobUrl = "https://" + $DstStorageName + ".blob.core.windows.net/$DstTempContainer"
    $DstTableUrl = "https://" + $DstStorageName + ".table.core.windows.net"

    # Create container in destination blob
    Write-Host "$DstTempContainer is not existing in $DstStorageName..."
    Write-Host "Creating container $DstTempContainer in $DstStorageName..."
    New-AzureStorageContainer -Name $DstTempContainer -Permission Off -Context $DstContext

    # Get all tables from source
    $SrcTables = Get-AzureStorageTable -Name "*" -Context $SrcContext
    foreach($table in $SrcTables)
    {
        $TableName = $table.Name                
        Write-Host "Table $TableName"

        # Validate if copy all table from source
        # Validate if table name is included in our list
        if(!$IncludeTable.Contains("All") -and !$IncludeTable.Contains($TableName))
        {
           Write-Host "Skipping table $TableName"
           return
        }
                
        Write-Host "Migrating Table $TableName"      
        $SrcTableUrl = $SrcBaseUrl + $TableName

        # Copy Table from source to blob destination. As far as I know there is way no way to copy table to table directly.
        # Alternatively, we will copy the table temporaryly into destination blob.
        # Take note to put the actual path of AzCopy.exe
        Write-Host "Start exporting table $TableName..."
        Write-Host "From    : $SrcTableUrl"
        Write-Host "To      : $DstBlobUrl/$TableName"

        AzCopy /Source:$SrcTableUrl `
                          /Dest:$DstBlobUrl/$TableName `
                          /SourceKey:$SrcAccessKey `
                          /Destkey:$DstAccessKey
   
        # Get the newly created blob
        Write-Host "Get all blobs in $DstTempContainer..."
        $CurrentBlob = Get-AzureStorageBlob -Container $DstTempContainer -Prefix $TableName -Context $DstContext

        # Loop and check manifest, then import blob to table
        foreach($blob in $CurrentBlob)
        {
            if(!$blob.Name.contains('.manifest'))
            {
                return
            }

            $manifest = $($blob.Name).split('/')[1]

            Write-Host "Start importing $TableName..."
            Write-Host "Source blob url : $DstBlobUrl/$TableName"
            Write-Host "Dest table url  : $DstTableUrl/$TableName"           
            Write-Host "Manifest name   : $manifest"
                
            # Import blob to table. Insert entity if missing and update entity if exists
            AzCopy /Source:$DstBlobUrl/$TableName `
                              /Dest:$DstTableUrl/$TableName `
                              /SourceKey:$DstAccessKey `
                              /DestKey:$DstAccessKey `
                              /Manifest:$manifest `
                              /EntityOperation:"InsertOrReplace"            
        }
    }

    # Delete temp table storage after export and import process
    Write-Host "Removing $DstTempContainer from destination blob storage..."
    Remove-AzureStorageContainer -Name $DstTempContainer -Context $DstContext -Force
}

# Login
function Azure-Login
{
    $needLogin = $true

    Try 
    {
        $content = Get-AzureRmContext

        if ($content) 
        {
            $needLogin = ([string]::IsNullOrEmpty($content.Account))
        } 
    } 
    Catch 
    {
        if ($_ -like "*Login-AzureRmAccount to login*") 
        {
            $needLogin = $true
        } 
        else 
        {
            throw
        }
    }

    if ($needLogin)
    {
        Login-AzureRmAccount
    }
}


Solution 1:[1]

Azure Portal cloud shell shows to be using AzCopy version 10.6.1 as of 2021.11.10. The ability to copy between tables has been removed after version 7.3. enter image description here

You need to run the script from a machine where you can download the older version of AzCopy.

Solution 2:[2]

My solution was just running a command:

Install-Module -Name Az -Scope CurrentUser -Repository PSGallery -Force

in the powershell

Before: enter image description here

azcopy now works enter image description here and the script now works: enter image description here

Hope it helps

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Stringfellow
Solution 2 Mr.B