【问题标题】:how to connect storage account to AAS using powershell script in azure function如何在 azure 函数中使用 powershell 脚本将存储帐户连接到 AAS
【发布时间】:2022-02-08 19:52:50
【问题描述】:

## 获取要从中检索容器的存储帐户

$StorageKey = Get-AzStorageAccountKey -ResourceGroupName $resourceGroupName -Name $storageAccName 

出现错误: [错误] Import-AzContext:术语“Import-AzContext”未被识别为 cmdlet、函数、脚本文件或可运行程序的名称。检查名称的拼写,或者如果包含路径,请验证路径是否正确并重试。在 run.ps1:第 3 行+ Import-AzContext+ ________________+ CategoryInfo : ObjectNotFound: (Import-AzContext:String) [] , CommandNotFoundException+FullyQualifiedErrorId : CommandNotFoundException 2022-02-08T10:26:01.327 [错误]:由于缺少一个或多个强制参数,无法处理命令:Name.at run.ps1:第 4+++ 行 CategoryInfo:InvalidArgument:(:) [Import-Module], ParameterBindingException+ FullyQualifiedErrorId : MissingMandatoryParameter,Microsoft.PowerShell.Commands.ImportModuleCommand,run.ps1 2022-02-08T10:26:01.468 [错误] 参数:术语“参数”未被识别为 cmdlet、函数、脚本文件或可运行程序的名称。检查名称的拼写,或者如果包含路径,请验证路径是否正确并重试。在 run.ps1:第 7 行+ param+ _____+ CategoryInfo : ObjectNotFound: (param:String) [], CommandNotFoundException+ FullyQualifiedErrorId : CommandNotFoundException 2022-02-08T10:26:01.546 [错误] 执行函数时出现异常:Functions.HttpTrigger2。 Microsoft.Azure.WebJobs.Script:PowerShell 脚本错误。 System.Management.Automation:术语“Import-AzContext”未被识别为 cmdlet、函数、脚本文件或可运行程序的名称。检查名称的拼写,或者如果包含路径,请验证路径是否正确并重试。 2022-02-08T10:26:01.561 [错误] 功能完成(失败,Id=2339b513-6a62-4687-b418-c31db73fd8c8,持续时间=408ms)

【问题讨论】:

标签: azure powershell


【解决方案1】:

当我从我的 PowerShell Get-AzStorageAccountKey -ResourceGroupName MyResourceGroupName -Name MyStorageAccountName 运行此命令时,它显示如下输出:

如果您想要的输出是这样的,那么您可以通过运行以下命令更新您的 PowerShell Az 模块:Update-Module Az -Force

更新成功后重试。

如果您还没有安装Az 模块,那么您需要先安装该模块。您可以按照以下步骤操作:

安装 Azure Az PowerShell 模块

Azure Az PowerShell 模块是一个汇总模块。安装它会下载普遍可用的 Az PowerShell 模块,并使其 cmdlet 可供使用。 在 PowerShell 7.0.6 LTS 和 PowerShell 7.1.3 或更高版本上运行时,Azure PowerShell 没有其他要求。要检查您的 PowerShell 版本,请在 PowerShell 会话中运行以下命令:

$PSVersionTable.PSVersion 

here 安装适用于您的操作系统的最新版本的 PowerShell。

Azure Az PowerShell 模块也支持在 Windows 上与 PowerShell 5.1 一起使用。要在 Windows 上的 PowerShell 5.1 中使用 Azure Az PowerShell 模块:

  • 更新到 Windows PowerShell 5.1。如果您使用的是 Windows 10 版本 1607 或更高版本,则您已经安装了 PowerShell 5.1。
  • 安装.NET Framework 4.7.2 or later
  • 确保您拥有最新版本的 PowerShellGet。运行此命令。
Install-Module -Name PowerShellGet -Force

现在设置执行策略。 PowerShell 脚本执行策略必须设置为远程签名或限制较少。 Get-ExecutionPolicy -List 可用于确定当前的执行策略。运行这个命令:

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

使用 Install-Module cmdlet 是 Az PowerShell 模块的首选安装方法。仅为当前用户安装 Az 模块。这是推荐的安装范围。此方法在 Windows、macOS 和 Linux 平台上的工作方式相同。从 PowerShell 会话运行以下命令:

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

现在通过运行此命令更新 Az 模块。

Update-Module Az -Force

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-11-01
    • 2019-06-08
    • 1970-01-01
    • 1970-01-01
    • 2017-05-09
    • 2019-06-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多