标签:地址 absolute rtu rest str 存储 prim unity tomat
#-----------------------------------------------------------------用指定Blob中的vhd创建虚拟机---------------------------------------- #目标存储信息 $destStorageAccountName ="{存储账户名称}" #目标存储账户名称 $destContainerName ="{容器名称}" #VHD所在容器名称 $destStorageAccountKey ="{存储账户key}" #key $fileName="{镜像名称及扩展名}" #容器中文件的名称及扩张名 -xxxxxx.vhd #虚拟机信息 $resourceGroupName="DemoResourceGroup" #要创建资源组的名称 $vmname = "CreateVmTest" #虚拟机名称 $vmUser="azureuser" $vmSize="Standard_A4" $osType=1 #0-windows 1-Linux
#公共配置信息-默认即可,不用配置 $credlogin = New-Object System.Management.Automation.PSCredential ("{订阅账户名称}", $securePassword) $securePassword = ConvertTo-SecureString ‘{订阅登录密码}‘ -AsPlainText -Force #此密码也将作为虚拟机登录密码 $endpoint="core.chinacloudapi.cn" $fileAbsoluteUri="https://"+$sourceStorageAccountName+".blob."+$endpoint+"/"+$sourceContainerName+"/"+$fileName $locationStr="China North" $osdiskurl = "https://"+$destStorageAccountName+".blob."+$endpoint+"/"+$destContainerName+"/" #拷贝后的vhd所在存储账户url地址(不包含文件名) #登录并创建指定资源组 Login-AzureRmAccount -EnvironmentName AzureChinaCloud -Credential $credlogin New-AzureRmResourceGroup -Name $resourceGroupName -Location $locationStr -Force # Create a subnet configuration $subnetConfig = New-AzureRmVirtualNetworkSubnetConfig -Name mySubnet -AddressPrefix 192.168.1.0/24 # Create a virtual network $vnet = New-AzureRmVirtualNetwork -ResourceGroupName $resourceGroupName -Location $locationStr -Name MyVNet -AddressPrefix 192.168.0.0/16 -Subnet $subnetConfig -Force #创建一个公网IP地址: $publicIP=New-AzureRmPublicIpAddress -Name createstfromPIP -ResourceGroupName $resourceGroupName -Location $locationStr -AllocationMethod Dynamic -IpAddressVersion IPv4 -Force #新建 Get-AzureRmPublicIpAddress -Name createstfromPIP -ResourceGroupName $resourceGroupName #查看刚刚创建的公网IP信息 #创建可用性集: #$Availabilityset = New-AzureRmAvailabilitySet -Name cranetestAV -ResourceGroupName crane -Location $locationStr #创建网卡: $nic=New-AzureRmNetworkInterface -Name VHDNIC -ResourceGroupName $resourceGroupName -Location $locationStr -SubnetId $vnet.Subnets[0].Id -PublicIpAddressId $publicIP.Id -Force #配置要使用的存储账号以及系统盘名称: #$storage = Get-AzureRmStorageAccount -Name cranenorthtest -ResourceGroupName $resourceGroupName #$vmname = "whxCreateVmTest" $osdiskname = $vmname + "_OSDisk" #$osdiskurl = "https://ygwhxteststg.blob.core.chinacloudapi.cn/whx-vhd/community-15186-37f6baac-720f-4e49-b2f7-9c39f44a82f9-1.vhd" $vmOsDisk =$osdiskurl+$osdiskname+".vhd" $cred = New-Object System.Management.Automation.PSCredential ($vmUser, $securePassword) $osdiskAbsoluteUri=$osdiskurl+$fileName #生成虚拟机的配置,将新建的虚拟机放在虚拟网络:
if($osType.Equals(1))#linux创建 { $vmconfig = New-AzureRmVMConfig -VMName $vmname -VMSize $vmSize |` Set-AzureRmVMOperatingSystem -Linux -ComputerName $vmname -Credential $cred| ` Set-AzureRmVMOSDisk -Name $osdiskname -VhdUri $vmOsDisk -SourceImageUri $osdiskAbsoluteUri -CreateOption FromImage -Linux | ` Add-AzureRmVMNetworkInterface -Id $NIC.Id } if($osType.Equals(0)) #windows创建 { $vmconfig = New-AzureRmVMConfig -VMName $vmname -VMSize $vmSize |` Set-AzureRmVMOperatingSystem -Windows -ComputerName $vmname -Credential $cred| ` -ProvisionVMAgent -EnableAutoUpdate | ` Set-AzureRmVMOSDisk -Name $osdiskname -VhdUri $vmOsDisk -SourceImageUri $osdiskAbsoluteUri -Caching "ReadWrite" -CreateOption FromImage -Windows | ` Add-AzureRmVMNetworkInterface -Id $nic.Id -Primary }
#创建虚拟机: New-AzureRmVM -ResourceGroupName $resourceGroupName -Location $locationStr -VM $vmconfig $vmList = Get-AzureRmVM -ResourceGroupName $resourceGroupName $vmList.Name
使用azure powershell 在ARM下用指定vhd镜像来创建虚拟机
标签:地址 absolute rtu rest str 存储 prim unity tomat
原文地址:http://www.cnblogs.com/wanghaixing/p/7762844.html