Creating Virtual Machine Using Powershell




Creating Virtual Machine Using PowerShell 



The Virtual Machine is an OS that is installed on software that imitates dedicated hardware.The End user has same experience on VM as they would have on dedicated hardware.

 Now we are going to write a PowerShell Script that will Create a Virtual Machine for us 
We are  going to create a Windows Virtual Machine Windows Server 2016. Putting All  togather



# Silently Logging to Azure Portal
Select-AzureRmProfile -Path "login.json"
# Variables Declaration and Definition Area
#-------------------------------------------------------------------------
$RG="Osgroup"
$LOCATION="South Central US"
$VMNAME="osgroup" $NICName="osgroupNIC"
$PublciIPName="PIPOSGRP"
$DnsName="osgroupdns"
$VNetName="OsgroupVNET"
$SubNetName="OsgroupSubnet1"
$NSGNAME="OsgroupNSG"
#------------------------------------------------------------------------
# Storing The Credentials for Azure Login to Vms
$CRED= Get-Credential
# NSG
$Rule1=New-AzureRmNetworkSecurityRuleConfig -Name "web-rule" -Description "allow all" `
-Access Allow -Protocol Tcp -Direction Inbound -Priority 100 -SourceAddressPrefix Internet `
-SourcePortRange "*" -DestinationAddressPrefix * -DestinationPortRange *


$NSG=New-AzureRmNetworkSecurityGroup -Name $NSGNAME -ResourceGroupName $RG -Location $LOCATION `
-SecurityRules $Rule1


# Pubic IP
$PIP=New-AzureRmPublicIpAddress -Name $PublciIPName -ResourceGroupName $RG -DomainNameLabel $DnsName `
-Location $LOCATION -AllocationMethod Static

# NIC
$vnet = Get-AzureRmVirtualNetwork -ResourceGroupName $RG -Name $VNetName

$NIC=New-AzureRmNetworkInterface -Name $NICName -ResourceGroupName $RG -Location $LOCATION `
-SubnetId $vnet.Subnets[0].id -PublicIpAddressId $PIP.Id -NetworkSecurityGroupId $NSG.Id



$VMCONFIG=New-AzureRmVMConfig -VMName $VMNAME -VMSize Standard_DS2 |`
Set-AzureRmVMOperatingSystem -Windows -ComputerName $VMNAME -Credential $CRED |`
Set-AzureRmVMSourceImage -PublisherName MicrosoftWindowsServer -Offer WindowsServer -Skus 2016-Datacenter -Version latest |`
Add-AzureRmVMNetworkInterface -Id $NIC.Id

New-AzureRmVM -ResourceGroupName $RG -Location $LOCATION -VM $VMCONFIG


Write-host"Have a nice time ahead!!! Thank you "

Popular posts from this blog

Certification for Kubernetes? I got it covered.

Continuous Integrations Concepts and Demo

Containers and Virtual Machines Explained || Containerization is new virtualization || DevOps