【问题标题】:Create Azure VM using PowerShell with Managed Disks using Market Place Image使用 PowerShell 和使用 Market Place 映像的托管磁盘创建 Azure VM
【发布时间】:2017-10-23 04:11:55
【问题描述】:

多年来我一直在摸不着头脑,找不到任何关于此的信息。所以有人可以告诉我如何使用 PowerShell 创建一个虚拟机,以便虚拟机在不使用ConvertTo-AzureRmVMManagedDisk 的情况下管理磁盘,并且基于像 Get-AzureRmVMImage -Location $location -PublisherName "MicrosoftWindowsServer" -Offer "WindowsServer" -Skus "2016-Datacenter" | Sort-Object Version -Descending | Select-Object -Index 0 这样的市场映像

谢谢。

【问题讨论】:

  • 如果您需要更多帮助,请告诉我:)

标签: powershell azure azure-managed-disk


【解决方案1】:

您的意思是要使用 PowerShell 创建一个带有托管 OS 磁盘的 Azure VM? 如果我理解正确的话,我们可以使用下面的 PowerShell 脚本来创建它:

$location = "eastus"

New-AzureRmResourceGroup -Name jasonvm -Location $location

# Create a subnet configuration
$subnetConfig = New-AzureRmVirtualNetworkSubnetConfig -Name mySubnet -AddressPrefix 192.168.1.0/24

# Create a virtual network
$vnet = New-AzureRmVirtualNetwork -ResourceGroupName jasonvm -Location $location `
    -Name MYvNET -AddressPrefix 192.168.0.0/16 -Subnet $subnetConfig

# Create a public IP address and specify a DNS name
$pip = New-AzureRmPublicIpAddress -ResourceGroupName jasonvm -Location $location `
    -AllocationMethod Static -IdleTimeoutInMinutes 4 -Name "mypublicdns$(Get-Random)"

# Create an inbound network security group rule for port 3389
$nsgRuleRDP = New-AzureRmNetworkSecurityRuleConfig -Name myNetworkSecurityGroupRuleRDP  -Protocol Tcp `
    -Direction Inbound -Priority 1000 -SourceAddressPrefix * -SourcePortRange * -DestinationAddressPrefix * `
    -DestinationPortRange 3389 -Access Allow

# Create an inbound network security group rule for port 80
$nsgRuleWeb = New-AzureRmNetworkSecurityRuleConfig -Name myNetworkSecurityGroupRuleWWW  -Protocol Tcp `
    -Direction Inbound -Priority 1001 -SourceAddressPrefix * -SourcePortRange * -DestinationAddressPrefix * `
    -DestinationPortRange 80 -Access Allow

# Create a network security group
$nsg = New-AzureRmNetworkSecurityGroup -ResourceGroupName jasonvm -Location $location `
    -Name myNetworkSecurityGroup -SecurityRules $nsgRuleRDP,$nsgRuleWeb

# Create a virtual network card and associate with public IP address and NSG
$nic = New-AzureRmNetworkInterface -Name myNic -ResourceGroupName jasonvm -Location $location `
    -SubnetId $vnet.Subnets[0].Id -PublicIpAddressId $pip.Id -NetworkSecurityGroupId $nsg.Id

# Define a credential object
$cred = Get-Credential

# Create a virtual machine configuration
$vmConfig = New-AzureRmVMConfig -VMName myVM -VMSize Standard_DS2_v2 | `
    Set-AzureRmVMOperatingSystem -Windows -ComputerName myVM -Credential $cred | `
    Set-AzureRmVMSourceImage -PublisherName MicrosoftWindowsServer -Offer WindowsServer `
    -Skus 2016-Datacenter -Version latest | Add-AzureRmVMNetworkInterface -Id $nic.Id

# Create the virtual machine
New-AzureRmVM -ResourceGroupName jasonvm -Location $location -VM $vmConfig

结果如下:

【讨论】:

  • 只是检查提供的信息是否有用。如果您需要进一步的帮助,请告诉我。
  • 嗨,杰森,我不敢相信事情就这么简单;我确信我尝试了所有 sigh。还有一件事,是否可以为磁盘命名我选择的名称?
  • @JohnE 目前,该脚本不支持指定操作系统磁盘名称。如果要指定OS盘名,请参考这个link。
  • @JohnE 该链接对您有用吗?如果您需要更多帮助,请告诉我:)
  • 我知道这是一篇旧帖子,但我们希望开始为我们的新 VM 操作系统使用托管磁盘。什么决定了操作系统是否是托管磁盘?它只是磁盘类型吗?作为您的示例,例如使用“Standard_DS2_v2”。
猜你喜欢
  • 2017-12-31
  • 2019-03-14
  • 1970-01-01
  • 1970-01-01
  • 2021-11-14
  • 2018-06-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多