linux - "New-AzureStorageContext"无法识别。 Linux

标签 linux powershell azure azure-blob-storage

我一直在运行一个脚本,将所有 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

最佳答案

请参阅此 question 和此 question

Unfortunately, I am finding that some older cmdlets are not supported yet though, since they are in an older module called Azure, which does not yet have a .NET Core implementation.

现在,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

这些 cmdlet 在 Linux Powershell 上受支持。

更新:

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

关于linux - "New-AzureStorageContext"无法识别。 Linux,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46300804/

相关文章:

powershell - MicrosoftTeams cmdlet 无法使用 AccessToken

Azure 恢复已删除的数据库

powershell - Azure 自动化、PowerShell 用于获取私有(private) blob 容器中的文件

azure - 从 Docker 容器将 Strapi SQLite 数据库保留在 Azure 应用服务 Linux 主机上

linux - 删除与特定字符串格式不匹配的文件

linux - 值的shell脚本比较

linux - 在 AWS Amazon Linux 上安装 MongoDB 时出错

c++ - 项目在 Windows 7 上运行,但无法在带有 Virtual Box 的 Linux 上运行

regex - Powershell 替换正则表达式

arrays - 在 Powershell 中,如何根据数组中字符串中的子字符串对数组进行排序?