1

I have the latest version of the Azure Powershell installed (0.9.7). I have a new virtual machine that was created via the Preview Portal. It was created with the new Resource Group model.

I am trying to install a few extensions but I cannot figure out the correct Powershell commands. Most instructions say to use Get-AzureVM. This does not return my VMs. If I use Switch-AzureMode to AzureResourceManager, I can use Get-AzureVM to list my VM (v2 I assume).

It seems none of the Extension scripts are setup for Resource Manager mode. Most of the sample scripts say to use: Get-AzureVM -ServiceName 'CLFeb19WS12R2A' -Name 'CLFeb19WS12R2A' | Set-AzureVMBGInfoExtension -Disable -ReferenceName 'BGInfo' | Update-AzureVM

I have tried all kinds of ways. The AzureVMBGInfoExtension cmdlet is not available in Resource Manager mode.

Any suggestions?

4

1 回答 1

2

创建虚拟机

我创建了一个新的 VM,以便为您提供帮助。我使用了 portal.azure.com > New > Compute > Marketplace > Windows Server > Windows Server 2008 R2 SP1 并选择了资源管理器部署模型。

创建 Active Directory 用户

由于我们使用的是 Azure 资源管理器,因此我需要创建一个新的 Active Directory 用户,以便我可以使用 Azure PowerShell 进行身份验证。这是我可以进行身份​​验证的唯一方法。

您可以使用以下步骤创建一个。

  1. 登录到 Azure 门户,然后选择 Active Directory。

  2. 如果不存在目录,请选择创建您的目录并提供请求的信息。

  3. 选择您的目录并添加一个新用户。此新用户是工作或学校帐户。

  4. 在创建用户期间,您将获得用户的电子邮件地址和临时密码。保存此信息,以备日后需要。

  5. 在 Azure 门户中,选择设置,然后选择管理员。选择添加,然后将新用户添加为共同管理员。这允许工作或学校帐户管理您的 Azure 订阅。

  6. 最后,注销 Azure 门户,然后使用新的工作或学校帐户重新登录。如果这是第一次使用此帐户登录,系统将提示您更改密码。

  7. 确保在以工作或学校帐户登录时看到您的订阅。

奇怪的是,如果我们使用其中一种类型的帐户进行身份验证,Azure 资源管理器似乎工作得最好(或只能工作)。

安装最新的 Azure PowerShell 模块

由于我们需要访问Extension相关的命令行开关,我安装了最新版本的 Azure PowerShell。该链接显示了如何通过 Web 平台安装程序进行安装。完成后,您可以通过运行以下命令来确定您是否拥有正确的:

> (Get-Module azureresourcemanager).Version

Major  Minor  Build  Revision
-----  -----  -----  --------
0      9      7      -1

当我们运行以下命令时,查看所有Extension相关的命令行开关。万岁!

> Switch-AzureMode -Name AzureResourceManager
> Get-Command *extension* -Module AzureResourceManager

Get-AzureVMAccessExtension            
Get-AzureVMCustomScriptExtension      
Get-AzureVMDiagnosticsExtension       
Get-AzureVMDscExtension               
Get-AzureVMExtension                  
Get-AzureVMExtensionImage             
Get-AzureVMExtensionImageType         
Remove-AzureVMAccessExtension         
Remove-AzureVMCustomScriptExtension   
Remove-AzureVMDiagnosticsExtension    
Remove-AzureVMDscExtension            
Remove-AzureVMExtension               
Set-AzureVMAccessExtension            
Set-AzureVMCustomScriptExtension      
Set-AzureVMDiagnosticsExtension       
Set-AzureVMDscExtension               
Set-AzureVMExtension

我们在资源管理器模式下可以访问这些。要了解如何使用它们中Get-Help Set-AzureVMAccessExtension -example的每一个,请在感兴趣的每个上运行。然后玩这个例子。

验证 Azure PowerShell 并为您的 VM 设置扩展

通过 进行身份验证时Add-AzureAccount,请使用我们创建的 Active Directory 用户。然后您可以查询您的虚拟机。

> Add-AzureAccount
> Get-AzureResource -ResourceType Microsoft.Compute/virtualMachines

了解 VM 的详细信息后,您可以添加扩展。这是一个对我有用的例子。

>  Set-AzureVMAccessExtension -ResourceGroupName "mvp1" -Location "West US" -VMName "mvp1" -Name "mvp1test" -TypeHandlerVersion "2.0" -UserName "shaunluttin" -Password "Password

EndTime             : 9/1/2015 9:35:57 PM -07:00
Error               :
Output              :
StartTime           : 9/1/2015 9:35:20 PM -07:00
Status              : Succeeded
TrackingOperationId : f03210e0-e67e-40d7-aad7-d9acef64bebe
RequestId           : 95f42767-edcf-443a-8977-4c9f6d0eafef
StatusCode          : OK

祝你好运。如果您有任何问题,请告诉我。

于 2015-09-02T04:21:34.647 回答