Skip to content

Instantly share code, notes, and snippets.

View esarabadani's full-sized avatar

Esmaeil Sarabadani esarabadani

View GitHub Profile
resources
| where type == "microsoft.compute/virtualmachines"
| extend id = tolower(tostring(properties.storageProfile.osDisk.managedDisk.id))
| project vm_name=name, id
| join (resources
| where type == "microsoft.compute/disks" and sku.name == "Premium_LRS"
| project name, id=tolower(id), type=sku.name) on id
| project vm_name, disk_id=id, type
resources
| where type =~ "Microsoft.Network/loadBalancers"
| mv-expand backendAddressPool=properties.backendAddressPools
| mv-expand ipconfig=backendAddressPool.properties.backendIPConfigurations
| extend ipconfig_id=tostring(ipconfig.id)
| project LB_name=name, ipconfig_id
| join (
resources
| where type =~ "Microsoft.Network/networkInterfaces"
| mv-expand ipconfig=properties.ipConfigurations
#Deploys a Virtual Machine Scale Set (with OS managed disk from an image) with an internal load balancer in front of it
#refer to this blog post for more information: https://wp.me/p9qR9L-5e
$Credential = Get-Credential
Add-AzureRmAccount -Credential $Credential
Select-AzureRmSubscription -SubscriptionId "Put your subscription ID here"
#This is your resource group in which your image, and all your other resources are located
$vmssObject = Get-AzureRmVmss -ResourceGroupName $greenrg -VMScaleSetName $vmssName
$vmssObject.virtualMachineProfile.storageProfile.osDisk.image.uri= $newImageURI
$instances = Get-AzureRmVmssVM -VMScaleSetName $vmssName -ResourceGroupName $greenrg
foreach($instance in $instances){
Update-AzureRmVmssInstance -ResourceGroupName $greenrg -VMScaleSetName $vmssName -InstanceId $instance.InstanceID
}
Add-AzureRmAccount
Select-AzureRmSubscription -SubscriptionId "Put your Azure Subscription ID here"
$greenrg = "bluegreen" #Enter the name of your resource group here
$loc = "West Europe" #Enter the region of your choice here
$vnetname = "bgvnet" #Enter the virtual network name here
$backendSubnetName = "subnet1" #This is the name of your subnet in the virtual network
$LBFrontendNewPrivateIPAddress = "10.1.0.6" #This is the frontend IP Address of your internal load balancer. Make sure it is in the same range as your subnet
$stName = "bgvmss" #This is the storage account name (for the scale set)
$vmssName = 'esmaeilbgvmss'; #This has to be a unique name and needs to be changed with every redeployment
#Login to Azure
Add-AzureRmAccount
#Select Azure Subscription
$subscription =
(Get-AzureRmSubscription |
Out-GridView `
-Title 'Select an Azure Subscription ...' `
-PassThru)
$azureCredential = Get-AutomationPSCredential -Name "AzMonkey"
if($azureCredential -ne $null)
{
Write-Output "Attempting to authenticate as: [$($azureCredential.UserName)]"
}
else
{
throw "No automation credential name was specified..."
}