Reputation: 117
Trying to run a powershell script to move a bunch of files on an Azure Storage Account using this command, as described here: docs
Move-AzDataLakeGen2Item -Context $context -Source $blob.Name -Destination $newBlobName
However getting the following error:
Line | 28 | Move-AzDataLakeGen2Item -Context $context -Source $blob.Name … | The 'Move-AzDataLakeGen2Item' command was found in the module 'Az.Storage', but the module could not be loaded due to the following error: [Assembly with same name is already loaded] For more information, run | 'Import-Module Az.Storage'.
Things I have done
Get-Module -ListAvailable Az.Storage
Directory: C:\Users\...\Documents\PowerShell\Modules
ModuleType Version PreRelease Name PSEdition ExportedCommands
Script 5.7.0 Az.Storage Core,Desk {Get-AzStorageAccount, Get-> AzStorageAccountKey, New-AzStorageAccount, New-AzStorageAccountKey…}
Running this .ps1 script via VSCode. Tried running it with both Windows Powershell or Powershell
Any ideas/thoughts would be helpful, thank you
Upvotes: 0
Views: 2078
Reputation: 10455
Move-AzDataLakeGen2Item -Context $context -Source $blob.Name … | The 'Move-AzDataLakeGen2Item' command was found in the module 'Az.Storage', but the module could not be loaded due to the following error: [Assembly with the same name is already loaded] For more information, run | 'Import-Module Az.Storage'.
The error message indicates that the Az.Storage
module is already loaded, but it can't be loaded again. This error occurs when you try to load the same module multiple times in the same session.
To resolve the issue, try to remove the module and import once again using the below commands.
Remove-module -Name Az.Storage
Import-Module Az.Storage
To check the modules are imported you can use the below commands:
Get-Module -Name Az.Storage -ListAvailable
Also, the issue often occurs because the script can't be performed from the system where it is currently working. you can notice that the option "Run" is disabled in the support tool if you try to build the command using Powershell ISE. This is because the current PowerShell policy has not been initiated by the user, which restricts the number of commands that may be executed.
You can set the execution policy to the current user by following commands.
Command:
set-ExecutionPolicy RemoteSigned -Scope CurrentUser
Once all was done, I tried with one CSV file to move from one filesystem to another filesystem with the below command.
Command:
Connect-azaccount
$ctx = New-AzStorageContext -StorageAccountName "venkat098" -UseConnectedAccount
Move-AzDataLakeGen2Item -FileSystem filesystem1 -Path directory1/results.csv -DestFileSystem filesystem2 -DestPath "test1/sample.csv" -Context $ctx
Output:
Portal:
Reference: Move-AzDataLakeGen2Item (Az.Storage) | Microsoft Learn
Upvotes: 0