Azure Powershell - 版本 1 中的 Switch-AzureMode 错误

Azure Powershell - Switch-AzureMode error in version 1

你好,我不是 powershell 程序员,我现在正在学习使用 pluralsight 和 exericese 文件给我错误,我认为这是因为 Azure Powershell 的版本从 0.9.8 更改为 1.0

这是错误:

c:\Pluralsight\chef-chef> .\Create-CourseEnvironmentARM.ps1
Switch-AzureMode : The term 'Switch-AzureMode' 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 C:\Pluralsight\chef-chef\Create-CourseEnvironmentARM.ps1:28 char:1
+ Switch-AzureMode AzureResourceManager -Verbose
+ ~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Switch-AzureMode:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Test-AzureResourceGroup : The term 'Test-AzureResourceGroup' 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 C:\Pluralsight\chef-chef\Create-CourseEnvironmentARM.ps1:32 char:5
+ if((Test-AzureResourceGroup -ResourceGroupName $GroupName) -eq $false){
+     ~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Test-AzureResourceGroup:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

New-AzureResourceGroupDeployment : The term 'New-AzureResourceGroupDeployment' 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 C:\Pluralsight\chef-chef\Create-CourseEnvironmentARM.ps1:44 char:1
+ New-AzureResourceGroupDeployment `
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (New-AzureResourceGroupDeployment:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

文件名:.\Create-CourseEnvironmentARM.ps1

I was searching error in google and confirm that azure power shell deprecate function "Switch-AzureMode AzureResourceManager -Verbose"

https://github.com/Azure/azure-powershell/wiki/Deprecation-of-Switch-AzureMode-in-Azure-PowerShell

Switch-AzureMode AzureResourceManager -详细

这是来自 Create-CourseEnvironmentARM 的代码。ps1

Switch-AzureMode AzureResourceManager -Verbose

### Create Resource Group ###

if((Test-AzureResourceGroup -ResourceGroupName $GroupName) -eq $false){
    New-AzureResourceGroup -Name $GroupName -Location $Location -Verbose
    $ResourceGroup = Get-AzureResourceGroup -Name $GroupName
    }
    else {$ResourceGroup = Get-AzureResourceGroup -Name $GroupName}

$parameters = @{
    'newStorageAccountName'="$StorageName";
    'adminUsername'="$AdminUsername";
    'dnsNameForPublicIP'="$PublicDNSName"
    }

New-AzureResourceGroupDeployment `
    -Name $DeploymentName `
    -ResourceGroupName $ResourceGroup.ResourceGroupName `
    -TemplateFile azuredeploy.json `
    -TemplateParameterObject $parameters `
    -Verbose

请帮助我更正此代码。我认为作者永远不会更新课程,而我当然在中间。我希望有人能帮我解决这个问题。

从 Powershell 的 v.1.0.0 开始就没有了 "Switch-AzureMode"。

ARM 和 ASM cmdlet 共存共存。 ASM cmdlet 的名称没有变化,但 ARM cmdlet 的名称现在都带有 RM。喜欢:

Add-AzureRmAccount

这两个 powershell cmdlet 都可以通过 Web 平台安装程序安装。

此外,在 Windows 10 上,可以使用以下命令(在 Aministrative PowerShell 控制台下)通过 PowerShell Gallery 安装 ARM cmdlet:

Install-Module AzureRM

确认所有被问到的问题。然后运行

Install-AzureRM

那么您就完成了 ARM 模块。只需确保您的本地执行策略至少为 "RemoteSigned".

最后,您必须编辑所有 PowerShell 脚本以匹配新的 cmdlet 及其参数。就像 New-AzureResourceGroup 现在是 New-AzureRmResourceGrouphttps://msdn.microsoft.com/en-us/library/mt603739.aspx