Azure PowerShell creates an arm unmanaged disk virtual machine using an existing image

Source: Internet
Author: User

Generate an image image file and record the URL of the image (the URL below is the test URL, please refer to the actual):
ImageURL:
Https://hlmrgstoragen.blob.core.chinacloudapi.cn/vhdscopy/hlmn4sysclocap-os-2017-09-21-2CE40CEE.vhd

Please refer to the corresponding installation documentation for steps to install and configure Azure PowerShell. After the installation configuration is complete, use the following command to create (#为注释, ignoring the corresponding instructions):

#指定虚拟机名称

$vmname = "Hlmsysr2n5"

#指定资源组

$resourceGroup = "Hlmrgn"

#指定区域位置

$location = "China North"

#指定虚拟网络

$vnetname = "Hlmrgvnetn"

#指定子网

$subnetname = "Default"

#指定公网IP名称

$publicipname = $vmname + "Pip"

#指定nsg名称

$nsgname = $vmname + "-NSG"

#指定网卡名称

$nicname = $vmname + "Nic"

#指定虚拟机磁盘名称

$osdiskname = $vmname + "-osdisk"

#指定OS磁盘缓存类型

$osdiskcaching = "ReadWrite"

#指定公网IP分配方式

$publicipallocationmethod = "Dynamic"

#指定创建机器的image文件位置

$sourceimageurl = "Https://hlmrgstoragen.blob.core.chinacloudapi.cn/vhdscopy/hlmn4sysclocap-os-2017-09-21-2CE40CEE.vhd"

#指定新建机器系统盘存放位置

$osdiskurl = "https://hlmrgstoragen.blob.core.chinacloudapi.cn/vhds/" + $osdiskname + ". vhd"

#查看Subnet

$vnet = Get-azurermvirtualnetwork-name $vnetname-resourcegroupname $resourceGroup

$subnet = Get-azurermvirtualnetworksubnetconfig-name $subnetname-virtualnetwork $vnet

#创建一个公网IP地址

$publicIP = new-azurermpublicipaddress-name $publicipname-resourcegroupname $resourceGroup-location $location- Allocationmethod $publicipallocationmethod-ipaddressversion Ipv4–force

#创建nsg安全规则

$nsgrule = New-azurermnetworksecurityruleconfig-name "DEFAULT-ALLOW-RDP"-description "Allow RDP"-access allow- Protocol tcp-direction inbound-priority 1000-sourceaddressprefix *-sourceportrange *-destinationaddressprefix *-Dest Inationportrange 3389

$NSG = new-azurermnetworksecuritygroup-name $nsgname-resourcegroupname $resourceGroup-location $location- Securityrules $nsgrule

#创建网卡

$nic = new-azurermnetworkinterface-name $nicname-resourcegroupname $resourceGroup-location $location-subnetid $ Subnet. Id-publicipaddressid $publicIP. Id-networksecuritygroupid $NSG. Id

#设置用户名及密码

$credential = get-credential-message "Type the name and password of the local administrator account."

#生成虚拟机的配置

$vmconfig = new-azurermvmconfig-vmname $vmname-vmsize standard_a2 | Set-azurermvmoperatingsystem-windows-computername $vmname-credential $credential-provisionvmagent- EnableAutoUpdate | Set-azurermvmosdisk-name $osdiskname-vhduri $osdiskurl-sourceimageuri $sourceimageurl-caching $osdiskcaching- Createoption Fromimage-windows | Add-azurermvmnetworkinterface-id $nic. Id-primary

#创建虚拟机

New-azurermvm-resourcegroupname $resourceGroup-location $location-VM $vmconfig

All the script commands are as follows:

$vmname="Hlmsysr2n5"$resourceGroup="Hlmrgn"$location=" North"$vnetname="HLMRGVNETN"$subnetname="default"$publicipname=$vmname+"Pip"$nsgname=$vmname+"-NSG"$nicname=$vmname+"Nic"$osdiskname=$vmname+"-osdisk"$osdiskcaching="ReadWrite"$publicipallocationmethod="Dynamic"$sourceimageurl="Https://hlmrgstoragen.blob.core.chinacloudapi.cn/vhdscopy/hlmn4sysclocap-os-2017-09-21-2CE40CEE.vhd"$osdiskurl="https://hlmrgstoragen.blob.core.chinacloudapi.cn/vhds/"+$osdiskname+". VHD" $vnet= Get-azurermvirtualnetwork-name$vnetname-resourcegroupname$resourceGroup$subnet= Get-azurermvirtualnetworksubnetconfig-name$subnetname-virtualnetwork$vnet$publicIP= New-azurermpublicipaddress-name$publicipname-resourcegroupname$resourceGroup-location$location-allocationmethod$publicipallocationmethod-ipaddressversion Ipv4–force$nsgrule= New-azurermnetworksecurityruleconfig-name"DEFAULT-ALLOW-RDP"-description"Allow RDP"-access allow-protocol tcp-direction inbound-priority 1000-sourceaddressprefix *-sourceportrange *-DestinationAddres Sprefix *-destinationportrange 3389$NSG= New-azurermnetworksecuritygroup-name$nsgname-resourcegroupname$resourceGroup-location$location-securityrules$nsgrule$nic= New-azurermnetworkinterface-name$nicname-resourcegroupname$resourceGroup-location$location-subnetid$subnet. Id-publicipaddressid$publicIP. Id-networksecuritygroupid$NSG. Id$credential= Get-credential-message"Type the name and password of the local administrator account." $vmconfig= New-azurermvmconfig-vmname$vmname-vmsize STANDARD_A2 | Set-azurermvmoperatingsystem-windows-computername$vmname-credential$credential-provisionvmagent-enableautoupdate | Set-azurermvmosdisk-name$osdiskname-vhduri$osdiskurl-sourceimageuri$sourceimageurl-caching$osdiskcaching-createoption Fromimage-windows | Add-azurermvmnetworkinterface-id$nic. Id-primarynew-azurermvm-resourcegroupname$resourceGroup-location$location-vm$vmconfig

Command execution succeeded:

Virtual machines that are created can successfully connect using:

Note:

The Linux virtual machine needs to be modified as follows three points:

The name and port of the 1.NSG rule

2. Command: Set-azurermvmoperatingsystem, parameters

3. Command: Set-azurermvmosdisk, parameters

Provides a script command to create a Linux machine:

$vmname="Hlmsys69n4"$resourceGroup="Hlmrgn"$location=" North"$vnetname="HLMRGVNETN"$subnetname="default"$publicipname=$vmname+"Pip"$nsgname=$vmname+"-NSG"$nicname=$vmname+"Nic"$osdiskname=$vmname+"-osdisk"$osdiskcaching="ReadWrite"$publicipallocationmethod="Dynamic"$sourceimageurl="Https://hlmrgstoragen.blob.core.chinacloudapi.cn/vhdscopy/hlm69n4wadclocap-os-2017-09-25-723993A1.vhd"$osdiskurl="https://hlmrgstoragen.blob.core.chinacloudapi.cn/vhds/"+$osdiskname+". VHD" $vnet= Get-azurermvirtualnetwork-name$vnetname-resourcegroupname$resourceGroup$subnet= Get-azurermvirtualnetworksubnetconfig-name$subnetname-virtualnetwork$vnet$publicIP= New-azurermpublicipaddress-name$publicipname-resourcegroupname$resourceGroup-location$location-allocationmethod$publicipallocationmethod-ipaddressversion Ipv4–force$nsgrule= New-azurermnetworksecurityruleconfig-name"Default-allow-ssh"-description"Allow SSH"-access allow-protocol tcp-direction inbound-priority 1000-sourceaddressprefix *-sourceportrange *-DestinationAddres Sprefix *-destinationportrange 22$NSG= New-azurermnetworksecuritygroup-name$nsgname-resourcegroupname$resourceGroup-location$location-securityrules$nsgrule$nic= New-azurermnetworkinterface-name$nicname-resourcegroupname$resourceGroup-location$location-subnetid$subnet. Id-publicipaddressid$publicIP. Id-networksecuritygroupid$NSG. Id$credential= Get-credential-message"Type the name and password of the local administrator account." $vmconfig= New-azurermvmconfig-vmname$vmname-vmsize STANDARD_A2 | Set-azurermvmoperatingsystem-linux-computername$vmname-credential$credential| Set-azurermvmosdisk-name$osdiskname-vhduri$osdiskurl-sourceimageuri$sourceimageurl-caching$osdiskcaching-createoption Fromimage-linux | Add-azurermvmnetworkinterface-id$nic. Id-primarynew-azurermvm-resourcegroupname$resourceGroup-location$location-vm$vmconfig

Successful execution:

Virtual machines that are created can successfully connect using:

Note:

When you create a virtual machine using image, the image can be reused.

Azure PowerShell creates an arm unmanaged disk virtual machine using an existing image

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.