千家信息网

Azure powershell使用平台镜像创建ARM非托管磁盘虚拟机

发表于:2024-11-25 作者:千家信息网编辑
千家信息网最后更新 2024年11月25日,Select-AzureRmSubscription -SubscriptionName "xxxxxxxx" # 选择订阅环境# 网络选项$myVirtualNetworkResourceGroup
千家信息网最后更新 2024年11月25日Azure powershell使用平台镜像创建ARM非托管磁盘虚拟机


Select-AzureRmSubscription -SubscriptionName "xxxxxxxx" # 选择订阅环境

# 网络选项

$myVirtualNetworkResourceGroup = " xxxxxxxx " # 虚拟网络资源组

$myVirtualNetworkName = " xxxxxxxx " # 虚拟网络

$myVirtualNetworkSubnetName = " xxxxxxxx " # 虚拟子网

$myResourceGroupName = " xxxxxxxx "

$myLocation = " xxxxxxxx "

$myAvailabilitySetName = " xxxxxxxx "

$myNetworkInterfaceName = " xxxxxxxx "

$myPublicIpAddressName = " xxxxxxxx "

$myDomainName = " xxxxxxxx "

$myLoadBalancerFrontendName = " xxxxxxxx " # 负载均衡器前端名称

$myLoadBalancerBackendName = " xxxxxxxx " # 负载均衡器后端名称

$myLoadBalanceName = " xxxxxxxx "

$myStorageAccountName = " xxxxxxxx "

# $myOSDiskUri = "http://" + $myStorageAccountName + ".blob.core.chinacloudapi.cn/vhds/" + "myOSDisk.vhd"

$myVMName = " xxxxxxxx "

$myVMSize = "Standard_D3_V2"

$myUsername = "leo" ###自定义用户名称

$myPassword = "xxxxxxxx" ###虚拟机账户密码

# 创建资源组

$myResourceGroup = New-AzureRmResourceGroup -Name $myResourceGroupName -Location $myLocation

# 创建可用性集

$myAvailabilitySet = New-AzureRmAvailabilitySet -Location $myLocation -Name $myAvailabilitySetName -ResourceGroupName $myResourceGroupName

# 创建存储账号

$myStorageAccount = New-AzureRMStorageAccount -Location $myLocation -Name $myStorageAccountName -ResourceGroupName $myResourceGroupName -SkuName Standard_LRS

# 创建公共IP地址

$myPublicIpAddressName = New-AzureRmPublicIpAddress -ResourceGroupName $myResourceGroupName -AllocationMethod Dynamic -Name $myPublicIpAddressName -Location $myLocation -DomainNameLabel $myDomainName

# 创建前端池

$myLoadBalancerFrontend = New-AzureRmLoadBalancerFrontendIpConfig -Name $myLoadBalancerFrontendName -PublicIpAddress $myPublicIpAddressName

# 创建后端池

$myLoadBalancerBackend = New-AzureRmLoadBalancerBackendAddressPoolConfig -Name $myLoadBalancerBackendName

# 创建负载均衡集

$myLoadBalancer = New-AzureRmLoadBalancer -Location $myLocation -Name $myLoadBalanceName -ResourceGroupName $myResourceGroupName -FrontendIpConfiguration $myLoadBalancerFrontend -BackendAddressPool $myLoadBalancerBackend

# 新建网络接口

$myVirtualNetwork = Get-AzureRmVirtualNetwork -ResourceGroupName $myVirtualNetworkResourceGroup -Name $myVirtualNetworkName

$myVirtualNetworkSubnet = Get-AzureRmVirtualNetworkSubnetConfig -VirtualNetwork $myVirtualNetwork -Name $myVirtualNetworkSubnetName

$myNetworkInterface = New-AzureRmNetworkInterface -Name $myNetworkInterfaceName -ResourceGroupName $myResourceGroupName -Location $myLocation -Subnet $myVirtualNetworkSubnet -LoadBalancerBackendAddressPool $myLoadBalancerBackend

# 创建登陆凭证

$myCred = New-Object System.Management.Automation.PSCredential($myUsername, (ConvertTo-SecureString $myPassword -AsPlainText -Force))

# 系统磁盘路径

$myURL = "http://" + $myStorageAccountName + ".blob.core.chinacloudapi.cn/vhds/" + $myVMName + "myOSDisk.vhd"

# 虚拟机配置

$vmConfig = New-AzureRmVMConfig -VMName $myVMName -VMSize $myVMSize -AvailabilitySetId $myAvailabilitySet.Id | `

Set-AzureRmVMOperatingSystem -Windows -ComputerName $myVMName -Credential $myCred | `

Set-AzureRmVMSourceImage -PublisherName MicrosoftWindowsServer -Offer WindowsServer -Skus 2016-Datacenter-zhcn -Version latest | `

Add-AzureRmVMNetworkInterface -Id $myNetworkInterface.Id | `

Set-AzureRmVMOSDisk -CreateOption FromImage -VhdUri $myURL -Windows

# 创建虚拟机

$myVM = New-AzureRmVM -ResourceGroupName $myResourceGroupName -Location $myLocation -VM $vmConfig


0