【问题标题】:"New-AzureStorageContext" not recognized. Linux“New-AzureStorageContext”无法识别。 Linux
【发布时间】:2023-03-04 11:30:01
【问题描述】:

我一直在运行一个脚本,将我的所有 BLOB 文件下载到我的 Windows 机器上。我没有问题。现在我正在尝试在我的 Ubuntu 16.10 上做同样的事情。

我已经在我的发行版上安装了 PowerShell。当我尝试运行我的脚本时:

Clear-Host
$SubscriptionName = "MySubName"
$StorageAccountName = "MyStorageAccountName" 
$StorageAccountKey = "SecretKey"
$ContainerName = "MyContainerName"
$localTargetDirectory = "/home/"

#Set up the storage account context 
$ctx = New-AzureStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $StorageAccountKey

Get-AzureStorageContainer -Context $ctx

$blobs = Get-AzureStorageBlob -Container $ContainerName -Context $ctx

foreach($Blob in $blobs){
    Get-AzureStorageBlobContent -Blob $Blob.Name -Container $ContainerName -Destination $localTargetDirectory -Context $ctx -Force
    }

PowerShell 无法识别多个命令。

New-AzureStorageContext : The term 'New-AzureStorageContext' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At /home/file.ps1

所以我尝试安装 AzureRM 模块:

PS /home> Install-Module AzureRM

它有效。现在我导入模块:

PS /home> Import-Module AzureRM
Import-Module : The specified module 'AzureRM' was not loaded because no valid     module file was found in any module directory.
At line:1 char:1
+ import-module <<<<  azurerm
+ CategoryInfo          : ResourceUnavailable: (azurerm:String) [Import-    Module], FileNotFoundException + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand

如何解决这个问题?可以直接下载模块文件放到模块目录下吗?

编辑: 我尝试像这样手动下载AzureRM模块(4.3.1版):

PS /home> Save-Module -Name AzureRM -Path ~/.local/share/powershell/modules/ -RequiredVersion 4.3.1
PS /home> Install-Module -Name AzureRM

模块确实下载了,安装没有输出,仍然无法工作。

编辑:

我发现了另一个不使用 PowerShell 的工具。 AzCopy

【问题讨论】:

  • 您好,您的存储帐户是经典模式存储帐户吗?现在,Linux 不支持经典的 Azure PowerShell cmdlet。
  • 我没有找到经典的符号。我猜这是一个新的存储帐户。

标签: linux powershell azure azure-blob-storage


【解决方案1】:

请参考这个question和这个question

不幸的是,我发现一些较旧的 cmdlet 不受支持 然而,由于它们位于一个名为 Azure 的旧模块中,它确实 还没有 .NET Core 实现。

现在,Linux PowerShell 支持AzureRM.Netcore

Install-Module -Name AzureRM.Netcore

目前,它仅支持 ARM cmdlet。很遗憾,不支持New-AzureStorageContext

如果您使用 ARM 存储帐户,则可以安装 AzureRM.Storage.Netcore

Get-AzureRmStorageAccount Get-AzureRmStorageAccountKey New-AzureRmStorageAccount New-AzureRmStorageAccountKey Remove-AzureRmStorageAccount Set-AzureRmCurrentStorageAccount Set-AzureRmStorageAccount Get-AzureRmStorageAccountNameAvailability Get-AzureRmStorageUsage

Linux Powershell 支持这些 cmdlet。

更新:

现在,Linux 支持 Azcopy,您可以使用 Azcopy 传输文件或目录,请参考link:Transfer data with AzCopy on Linux

【讨论】:

  • 我不知道我是否可以使用 AzureRM.Storage.Netcore 完成相同的任务(下载我的 blob 文件)我必须阅读更多文档。
  • 如果您的存储帐户是arm模式,您可以使用$storKey = (Get-AzureRmStorageAccountKey -Name $storAccount -ResourceGroupName $rgName ).Key1
  • @BeGreen 感谢您的分享,Azcopy 可以在 Linux 上运行,我将其添加到我的答案中。 Linux 上的 Power Shell 不支持 Azure 经典 cmdlet。 Azcopy 是一个不错的选择。
  • @BeGreen 我根据我的知识进行测试,对于您的场景,Linux 上的 powershell 无法支持。
猜你喜欢
  • 1970-01-01
  • 2019-06-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-02-04
  • 1970-01-01
  • 1970-01-01
  • 2021-07-31
相关资源
最近更新 更多