Powershell Script to add a disk to Azure RM virtual machine.
$Credentials = Get-Credential
param([string] $VirtualMachineName,$DiskSize)
Login-AzureRmAccount -EnvironmentName AzureUSGovernment -Credential $Credentials
$Managed_Prod_Sub = Get-AzureRMSubscription -SubscriptionId "Your subscription id"
Select-AzureRMSubscription -SubscriptionId $Managed_Prod_Sub.SubscriptionId ##
$Managed_ProdVMS = Get-AzureRMVM
if($VM.name -eq $VirtualMachineName)
{
Write-host "Working on $($VM.name)" -ForegroundColor Yellow
$rgName = $VM.ResourceGroupName
$vmName = $VM.Name
$location = $VM.location
$storageType = 'Premium_LRS'
$dataDiskName = $vmName + '_datadisk1'
$diskConfig = New-AzureRmDiskConfig -AccountType PremiumLRS -Location $location -CreateOption Empty -DiskSizeGB $DiskSize -OsType Windows
$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
}
$Credentials = Get-Credential
param([string] $VirtualMachineName,$DiskSize)
Login-AzureRmAccount -EnvironmentName AzureUSGovernment -Credential $Credentials
$Managed_Prod_Sub = Get-AzureRMSubscription -SubscriptionId "Your subscription id"
Select-AzureRMSubscription -SubscriptionId $Managed_Prod_Sub.SubscriptionId ##
$Managed_ProdVMS = Get-AzureRMVM
if($VM.name -eq $VirtualMachineName)
{
Write-host "Working on $($VM.name)" -ForegroundColor Yellow
$rgName = $VM.ResourceGroupName
$vmName = $VM.Name
$location = $VM.location
$storageType = 'Premium_LRS'
$dataDiskName = $vmName + '_datadisk1'
$diskConfig = New-AzureRmDiskConfig -AccountType PremiumLRS -Location $location -CreateOption Empty -DiskSizeGB $DiskSize -OsType Windows
$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
}