I wanted to install Windows Server 2016,but in that case,VM has no Public IP and NIC is not associated to any security group (Connect option grayed out),but all works as expected with Windows Server 2012 R2 !!???,is it bug or something else,i don’t know
For creating VM we need Azure Power Shell (see this blog for reference).First step is to create Resource Group.Resource Group can be seen as container for storing Azure resources (Virtual machines,Networks,Subnets,Storage accounts..).
This is resource group content i created in one of my previous posts
New-AzureRmResourceGroup -Name "My_Resource_Group" -Location "West Europe"
We also need Azure Storage Account.With this account we have access to Azure Storage services such as Tables, Queues, Files, Blobs and Azure virtual machine disks
Binary Large Object (BLOB) collection of bytes that can be used
to store anything (up to 200 TB)
Tables are used to store large amounts of data for massive scale where some basic structure is required, but relationships between data don’t need to be maintained.
Queues provide reliable and persistent messaging between applications
within Azure
Files provide an easy method to share storage within an Azure region
When creating a storage account, we can select one of the following replication options:
Locally redundant storage (LRS) replicates your data three times within a storage scale unit which is hosted in a datacenter in the region in which you created your storage account. A write request returns successfully only once it has been written to all three replicas. These three replicas each reside in separate fault domains and upgrade domains within one storage scale unit.
Zone-redundant storage (ZRS) replicates your data asynchronously across datacenters within one or two regions in addition to storing three replicas similar to LRS, thus providing higher durability than LRS. Data stored in ZRS is durable even if the primary datacenter is unavailable or unrecoverable
Geo-redundant storage (GRS) replicates your data to a secondary region that is hundreds of miles away from the primary region. If your storage account has GRS enabled, then your data is durable even in the case of a complete regional outage or a disaster in which the primary region is not recoverable.
Read-access geo-redundant storage (RA-GRS) maximizes availability for your storage account, by providing read-only access to the data in the secondary location, in addition to the replication across two regions provided by GRS.
New-AzureRmStorageAccount -ResourceGroupName My_Resource_Group -Name myresourceaccount11201 -SkuName "Standard_LRS" -Kind "Storage" -Location 'west europe'
Creating Virtual Network:
Create subnet first:
$mySubnet = New-AzureRmVirtualNetworkSubnetConfig -Name "mySubnet" -AddressPrefix 192.168.2.0/24
Create Virtual Network and add subnet to it:
$myVnet = New-AzureRmVirtualNetwork -Name "myVnet" -ResourceGroupName My_Resource_Group -Location 'west europe' -AddressPrefix 192.168.2.0/24 -Subnet $mySubnet
We can also specify custom DNS server adding -DNSServer ‘ip address’ switch
Check IP Address Availability
We can check if address we want to assign to VM is in use:
Get-AzureRmVirtualNetwork -Name myvnet -ResourceGroupName My_Resource_Group | Test-AzureRmPrivateIPAddressAvailability -IPAddress "192.168.2.1"
Creating NIC and assigning IP address:
$myNIC = New-AzureRmNetworkInterface -Name "dc-01" -ResourceGroupName My_Resource_Group -Location 'west europe' -SubnetId $myVnet.Subnets[0].Id -PublicIpAddressId $myPublicIp.Id -PrivateIpAddress 192.168.2.4
Creating Public IP
In order for VM to comunicate with virtual network we need public IP (AllocationMethod can be static and dynamic)
$myPublicIp = New-AzureRmPublicIpAddress -Name "myPublicIp" -ResourceGroupName 'My_Resource_Group' -Location 'west europe' -AllocationMethod Dynamic
Creating local admin credentials:
We’ll store credentials in variable
$username = 'daredevil' $password = 'Password1234!' $passwordsec = convertto-securestring $password -asplaintext -force $creds = New-Object System.Management.Automation.PSCredential($username, $passwordsec)
Configuring VM-Set Size
$myVm = New-AzureRmVMConfig -VMName "dc-01" -VMSize "Standard_D2"
For all available VM sizes check out this link
Configuring VM-Set the computer name, operating system type, and credentials
$myVM = Set-AzureRmVMOperatingSystem -VM $myVM -Windows -ComputerName "dc-01" -Credential $creds -ProvisionVMAgent -EnableAutoUpdate
Configuring VM-Set the OS image:
$myVM = Set-AzureRmVMSourceImage -VM $myVM -PublisherName "MicrosoftWindowsServer" -Offer "WindowsServer" -Skus "2012-R2-Datacenter" -Version "latest"
Configuring VM-Add network interface:
$myVM = Add-AzureRmVMNetworkInterface -VM $myvm -Id $mynic.Id
Configuring VM-Define the name and location of the VM hard disk:
$storacct = Get-AzureRmStorageAccount -ResourceGroupName 'my_resource_group' –StorageAccountName 'myresourceaccount11201' $blobPath = "vhds/myOsDisk1.vhd" $osDiskUri = $storacct.PrimaryEndpoints.Blob.ToString() + $blobPath
With above commands,VM disk is created in storage account myresourceaccount11201
Configuring VM-Add hard disk to VM:
$vm = Set-AzureRmVMOSDisk -VM $myVM -Name "myOsDisk1" -VhdUri $osDiskUri -CreateOption fromImage
Create VM:
New-AzureRmVM -ResourceGroupName 'my_resource_group' -Location 'west europe' -VM $myVM