Creating a VM using powershell

powershell:
Connect-Azaccount –> after login page prompt, will get the account details displayed as object data.

$cred = get-credential –> for your VM.
$vm = New-AzVMConfig -VMName myVM -VMSize Standard_D1 –> just creating HardwareProfile for size.

#Remaining details of profile
$vm = Set-AzVMOperatingSystem -VM $vm `
>> -Windows `
>> -ComputerName myVM `
>> -Credential $cred `
>> -ProvisionVMAgent -EnableAutoUpdate

#Picking the image of OS
$vm = Set-AzVMSourceImage -VM $vm -PublisherName MicrosoftWindowsServer -Offer WindowsServer -Skus 2016-Datacenter -Version latest

So, we have set HardwareProfile, OSProfile, StorageProfile(ImageReference) which can be seen with $vm on console.

Now, set the storage harddisk type.
$vm = Set-AzVMOSDisk -VM $vm -Name myOsDisk -DiskSizeInGB 128 -CreateOption FromImage -Caching ReadWrite

Now, add network card.
copy the resource id from existing network card in azure portal.
$vm = Add-AzVMNetworkInterface -VM $vm -Id <NetworkInterfaceResourceId>

new-azvm -ResourceGroupName prod_it -Location EastUs -VM $vm
get-azvm | gm
Get-AzPublicIpAddress -ResourceGroupName <group_name>
mstsc /v:<publicip>

Leave a comment

Blog at WordPress.com.

Up ↑

Design a site like this with WordPress.com
Get started