Skip to content

Instantly share code, notes, and snippets.

@marckean
Last active May 26, 2017 01:56
Show Gist options
  • Save marckean/7f60f47169a3c44791232a891b9dd648 to your computer and use it in GitHub Desktop.
Save marckean/7f60f47169a3c44791232a891b9dd648 to your computer and use it in GitHub Desktop.
### Log into Azure ARM
Login-AzureRmAccount
### Choose Subscription
$subscription = (Get-AzureRmSubscription | Out-GridView -Title "Select the Azure subscription that you want to use ..." -PassThru).SubscriptionName
Select-AzureRmSubscription -SubscriptionName $subscription
##########################################################################################
########################## Select source Virtual Machine ###########################
##########################################################################################
#region Virtual Machines | @marckean
cls
Write-Host "`nGathering a list of all virtual machines in the 'old' ASM based Azure as well as their location and status..." -ForegroundColor Cyan
$VMs = Find-AzureRmResource -ExpandProperties | ? {$_.ResourceType -eq 'Microsoft.ClassicCompute/virtualMachines'} | `
select Name,Location,`
@{Name='CloudService';Expression={$_.ResourceGroupName}},`
@{Name='VirtualNetworkName';Expression={$_.properties.networkprofile.virtualnetwork.name}},`
@{Name='PowerState';Expression={$_.properties.instanceview.powerstate}}
$SourceVM = ($VMs | Out-GridView -Title "Select a VM in a Cloud Service - this script will gather information about the entire cloud service..." -PassThru)
$SourceCS = $SourceVM.CloudService
write-host -nonewline "`n`tThe virtual machine you selected is: " -ForegroundColor Yellow; `
write-host -nonewline $SourceVM.name`n -ForegroundColor Green; `
start-sleep -seconds 3
#endregion
##########################################################################################
#################### Capture source Cloud Service information ######################
##########################################################################################
#region Other details of the cloud service & virtual machine | @marckean
cls
Write-Host "`n`tGetting other details of the cloud service & virtual machine/s..." -ForegroundColor Cyan
####################### | Source Virtual Machine & Cloud Service information | ####################### | @marckean
$SourceResources = Find-AzureRmResource -ExpandProperties
$CSVMResources = $SourceResources | ? {$_.ResourceGroupName -eq $SourceCS -and $_.ResourceType -eq 'Microsoft.ClassicCompute/virtualMachines'}
$vNetName = ($CSVMResources.properties.networkprofile.virtualnetwork.name | select -Index 0)
$CSvNetResource = $SourceResources | ? {$_.ResourceName -eq $vNetName -and $_.ResourceType -eq 'Microsoft.ClassicNetwork/virtualNetworks'}
#endregion
#region Export results to files
$ClassicVMs = @()
$ClassicVMsPath = "$env:USERPROFILE\Desktop\AzureASMClassicVMsPath_{0}.json" -f $SourceCS
$ClassicvNetPath = "$env:USERPROFILE\Desktop\AzureASMClassicvNetPath_{0}.json" -f $SourceCS
foreach($CSVMResource in $CSVMResources){
$ClassicVMs += $CSVMResource | ConvertTo-Json -Depth 50
}
$CSvNetResource | ConvertTo-Json -Depth 50 | Out-File -FilePath $ClassicvNetPath
$ClassicVMs | Out-File -FilePath $ClassicVMsPath
#endregion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment