Advertisement
Guest User

Untitled

a guest
May 26th, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.92 KB | None | 0 0
  1. ### Log into Azure ARM
  2. Login-AzureRmAccount
  3.  
  4. ### Choose Subscription
  5. $subscription = (Get-AzureRmSubscription | Out-GridView -Title "Select the Azure subscription that you want to use ..." -PassThru).SubscriptionName
  6. Select-AzureRmSubscription -SubscriptionName $subscription
  7.  
  8. ##########################################################################################
  9. ########################## Select source Virtual Machine ###########################
  10. ##########################################################################################
  11.  
  12. #region Virtual Machines | @marckean
  13. cls
  14. Write-Host "`nGathering a list of all virtual machines in the 'old' ASM based Azure as well as their location and status..." -ForegroundColor Cyan
  15. $VMs = Find-AzureRmResource -ExpandProperties | ? {$_.ResourceType -eq 'Microsoft.ClassicCompute/virtualMachines'} | `
  16. select Name,Location,`
  17. @{Name='CloudService';Expression={$_.ResourceGroupName}},`
  18. @{Name='VirtualNetworkName';Expression={$_.properties.networkprofile.virtualnetwork.name}},`
  19. @{Name='PowerState';Expression={$_.properties.instanceview.powerstate}}
  20.  
  21. $SourceVM = ($VMs | Out-GridView -Title "Select a VM in a Cloud Service - this script will gather information about the entire cloud service..." -PassThru)
  22. $SourceCS = $SourceVM.CloudService
  23.  
  24. write-host -nonewline "`n`tThe virtual machine you selected is: " -ForegroundColor Yellow; `
  25. write-host -nonewline $SourceVM.name`n -ForegroundColor Green; `
  26. start-sleep -seconds 3
  27.  
  28. #endregion
  29.  
  30. ##########################################################################################
  31. #################### Capture source Cloud Service information ######################
  32. ##########################################################################################
  33.  
  34. #region Other details of the cloud service & virtual machine | @marckean
  35. cls
  36. Write-Host "`n`tGetting other details of the cloud service & virtual machine/s..." -ForegroundColor Cyan
  37. ####################### | Source Virtual Machine & Cloud Service information | ####################### | @marckean
  38. $SourceResources = Find-AzureRmResource -ExpandProperties
  39. $CSVMResources = $SourceResources | ? {$_.ResourceGroupName -eq $SourceCS -and $_.ResourceType -eq 'Microsoft.ClassicCompute/virtualMachines'}
  40. $vNetName = ($CSVMResources.properties.networkprofile.virtualnetwork.name | select -Index 0)
  41. $CSvNetResource = $SourceResources | ? {$_.ResourceName -eq $vNetName -and $_.ResourceType -eq 'Microsoft.ClassicNetwork/virtualNetworks'}
  42.  
  43. #endregion
  44.  
  45. #region Export results to files
  46.  
  47. $ClassicVMs = @()
  48.  
  49. $ClassicVMsPath = "$env:USERPROFILE\Desktop\AzureASMClassicVMsPath_{0}.json" -f $SourceCS
  50. $ClassicvNetPath = "$env:USERPROFILE\Desktop\AzureASMClassicvNetPath_{0}.json" -f $SourceCS
  51.  
  52. foreach($CSVMResource in $CSVMResources){
  53.  
  54. $ClassicVMs += $CSVMResource | ConvertTo-Json -Depth 50
  55.  
  56. }
  57.  
  58. $CSvNetResource | ConvertTo-Json -Depth 50 | Out-File -FilePath $ClassicvNetPath
  59. $ClassicVMs | Out-File -FilePath $ClassicVMsPath
  60.  
  61. #endregion
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement