Azure Power Shell Scripts
Create Availbility Set and Add Virutal Machine
$testName = "arjunrg"
$resourceGroupName = $testName
$location = "westus"
$domainName = "arjunrg1"
$subnetName = "Subnet-2"
$publisher = "MicrosoftWindowsServer"
$offer = "WindowsServer"
$sku = "2016-Datacenter"
$version = "latest"
$cred = Get-Credential
Get-AzureRmResourceGroup -Name $resourceGroupName -Location $location
$vip = New-AzureRmPublicIpAddress -ResourceGroupName $resourceGroupName -Name "VIP2" `
-Location $location -AllocationMethod Dynamic -DomainNameLabel $domainName
$subnet = New-AzureRmVirtualNetworkSubnetConfig -Name $subnetName `
-AddressPrefix "10.12.0.0/24"
$vnet = Get-AzureRmVirtualNetwork -Name "VNET" `
-Subnet $subnet
$subnet = Get-AzureRmVirtualNetworkSubnetConfig -Name $subnetName -VirtualNetwork $vnet
$nic2 = New-AzureRmNetworkInterface -ResourceGroupName $resourceGroupName `
-Name "nic2" -Subnet $subnet -Location $location
#New-AzureRmAvailabilitySet -ResourceGroupName $resourceGroupName `
#-Name "AVSet" -Location $location
$avset = Get-AzureRmAvailabilitySet -ResourceGroupName $resourceGroupName -Name "AVSet"
New-AzureRmStorageAccount -ResourceGroupName $resourceGroupName `
-Name $testName -Location $location -Type Standard_LRS
Get-AzureRmStorageAccount -ResourceGroupName $resourceGroupName
$vmName = "arjunrg-vmas2"
$vmConfig = New-AzureRmVMConfig -VMName $vmName -VMSize "Standard_A1" `
-AvailabilitySetId $avSet.Id |
Set-AzureRmVMOperatingSystem -Windows -ComputerName $vmName `
-Credential $cred -ProvisionVMAgent -EnableAutoUpdate |
Set-AzureRmVMSourceImage -PublisherName $publisher -Offer $offer -Skus $sku `
-Version $version |
Set-AzureRmVMOSDisk -Name $vmName -VhdUri "https://$testName.blob.core.windows.net/vhds/$vmName-os.vhd" `
-Caching ReadWrite -CreateOption fromImage |
Add-AzureRmVMNetworkInterface -Id $nic2.Id
New-AzureRmVM -ResourceGroupName $resourceGroupName -Location $location `
-VM $vmConfig
Create Virutal Machine and Attach disk
#https://docs.microsoft.com/en-us/azure/virtual-machines/windows/quick-create-powershell
# This link gives examples of the following script before the changes we made. See notes.
# update obvious names to something that makes sense for the user
$rgName = 'my_rg'
$vmName = 'myVM'
$location = 'East US'
Login-AzureRmAccount
New-AzureRmResourceGroup -Name $rgName -Location $location
New-AzureRmVm `
-ResourceGroupName $rgName `
-Name $vmName `
# Make sure to set this size rather than leaving to default
-Size "Standard_B1S" `
-Location $location `
-VirtualNetworkName "myVnet" `
-SubnetName "mySubnet" `
-SecurityGroupName "myNetworkSecurityGroup" `
-PublicIpAddressName "myPublicIpAddress" `
-OpenPorts 80,3389
#https://docs.microsoft.com/en-us/azure/virtual-machines/windows/attach-disk-ps
# This link gives examples of the following script before the changes we made. See notes.
#Make sure to change from PremiumLRS to StandardLRS
$storageType = 'StandardLRS'
$dataDiskName = $vmName + '_datadisk1'
#Make sure to set -DiskSizeGB to 32
$diskConfig = New-AzureRmDiskConfig -AccountType $storageType -Location $location -CreateOption Empty -DiskSizeGB 32
$dataDisk1 = New-AzureRmDisk -DiskName $dataDiskName -Disk $diskConfig -ResourceGroupName $rgName
$vm = Get-AzureRmVM -Name $vmName -ResourceGroupName $rgName
$vm = Add-AzureRmVMDataDisk -VM $vm -Name $dataDiskName -CreateOption Attach -ManagedDiskId $dataDisk1.Id -Lun 1
Update-AzureRmVM -VM $vm -ResourceGroupName $rgName
Create Web App and Deploy Git Rep.ps1
$gitRepo = "<repo url goes here>"
$webAppName = "<web app name goes here>"
$location = "<location goes here>"
$resourceGroup = "<resource name goes here>"
# Login
Login-AzureRmAccount
# Make a new resource group.
New-AzureRmResourceGroup -Name $resourceGroup -Location $location
# Create the 'Free' tier App Service plan.
New-AzureRmAppServicePlan -Name $webAppName `
-Location $location `
-ResourceGroupName $resourceGroup `
-Tier Free
# Create the web app.
New-AzureRmWebApp -Name $webAppName `
-Location $location `
-AppServicePlan $webAppName `
-ResourceGroupName $resourceGroup
# Configure GitHub deployment from your GitHub repo and deploy once.
$PropertiesObject = @{
repoUrl = "$gitRepo";
branch = "master";
isManualIntegration = "true";
}
Set-AzureRmResource -PropertyObject $PropertiesObject `
-ResourceGroupName $resourceGroup `
-ResourceType Microsoft.Web/sites/sourcecontrols `
-ResourceName $webAppName/web `
-ApiVersion 2015-08-01 `
-Force