我正在尝试运行一个在同事的计算机上运行的PowerShell脚本,但是在这一行上我的失败了:
Set-Variable -Name StorageContext -Value (New-AzureStorageContext -ConnectionString $storageConnectionString)
我的错误是:
New-AzureStorageContext:术语“New-AzureStorageContext”未被识别为cmdlet,函数,脚本文件或可操作程序的名称。检查名称的拼写,或路径是否正确 包含,验证路径是否正确,然后重试。 在C:\ Users \ dlogg \ Documents \ Repos \ sd2 \ PowerShell Scripts \ Eco \ AddEco.ps1:22 char:43 + Set-Variable -Name StorageContext -Value(New-AzureStorageContext -ConnectionStr ...
我已经确认我有PowerShell v.3,并且已经从Web PI安装了Azure PowerShell和Microsoft Azure SDK以及Microsoft Azure PowerShell(独立版)。我需要安装什么才能使用它?
http://msdn.microsoft.com/en-us/library/azure/dn495246.aspx
更新:根据下面的请求,我已包含Get-Module
的输出:
ModuleType Name ExportedCommands
---------- ---- ----------------
Script Common {Fetch, Get-BlobContainer, Get-ConfigurationFileName, Get-DeploymentTenantListFileName...}
Script ISE {Get-IseSnippet, Import-IseSnippet, New-IseSnippet}
Manifest Microsoft.PowerShell.Management {Add-Computer, Add-Content, Checkpoint-Computer, Clear-Content...}
Manifest Microsoft.PowerShell.Utility {Add-Member, Add-Type, Clear-Variable, Compare-Object...}
答案 0 :(得分:6)
您尚未加载Azure PowerShell模块(因此您的列表中缺少该模块)。安装Cmdlet时,您还将获得一个新的快捷方式" Microsoft Azure Powershell"它将自动为您加载模块(并使Cmdlet可用)。
如果您不想这样做,可以使用此命令将模块导入现有的PowerShell会话(请注意,Azure模块的路径可能因您安装的版本而异)。 / p>
Import-Module "C:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\ServiceManagement\Azure\Azure.psd1"
答案 1 :(得分:1)
您使用的是哪个版本的Azure PowerShell模块?您是否已加载Azure模块,或只是运行PowerShell(或通过Azure PowerShell快捷方式)。
以下是Azure PowerShell模块0.8.8.1
的输出PS C:\> Get-Module
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Manifest 0.8.8.1 Azure {Add-AzureAccount, Add-AzureCacheWorkerRole, Add-AzureCert...
Manifest 3.1.0.0 Microsoft.PowerShell.Management {Add-Computer, Add-Content, Checkpoint-Computer, Clear-Con...
Manifest 3.0.0.0 Microsoft.PowerShell.Security {ConvertFrom-SecureString, ConvertTo-SecureString, Get-Acl...
Manifest 3.1.0.0 Microsoft.PowerShell.Utility {Add-Member, Add-Type, Clear-Variable, Compare-Object...}
PS C:\> New-AzureStorageContext
cmdlet New-AzureStorageContext at command pipeline position 1
Supply values for the following parameters:
(Type !? for Help.)
StorageAccountName:
使用Azure PowerShell cmdlet的最佳方法是直接从安装程序生成的快捷方式启动Azure PowerShell。或使用Import-Module
命令导入Azure PowerShell模块。
有关详细说明,请阅读How to: Install and configure Azure Power Shell module。并查看this ServerFault question and answer。
答案 2 :(得分:1)
您需要像在microsoft站点中一样安装azure power shell https://docs.microsoft.com/en-us/powershell/azure/install-az-ps?view=azps-1.1.0
它就像一个魅力
答案 3 :(得分:1)
从网址安装Microsoft SDK for PowerShell - https://azure.microsoft.com/en-in/downloads/
重新启动Windows机器并尝试执行脚本。它将按预期工作
答案 4 :(得分:0)
我也有同样的问题。 我的问题是使用了错误的命令:“ AzureStorageContext”。它应该支持“ AzStorageContext”