Skip to content
This repository was archived by the owner on Oct 29, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 116 additions & 0 deletions 1-Collect/Get-RessourcesFromAM.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<#.SYNOPSIS
Parses Azure Migrate assessment data from an Excel file and extracts virtual machine and disk SKUs.
.DESCRIPTION
This script retrieves and processes Azure resource data from the output file generated by Azure Migrate, specifically focusing on virtual machine and disk SKUs.
It outputs the results in the same structured JSON format as Get-AzureServices.ps1, which can then be used for finding appropriate Azure regions where these resources can be deployed.
.PARAMETER filePath
The path to the Excel file containing the Azure Migrate assessment data.

.PARAMETER outputFile
The name of the output file where the results will be exported. Default is "resources.json".

.EXAMPLE
PS C:\> .\Get-RessourcesFromAM.ps1 -filePath "C:\path\to\Assessment.xlsx" -outputFile "C:\path\to\summary.json"
Runs the script with the specified Excel file and outputs the results to the specified JSON file.

.OUTPUTS
JSON file containing the queried resource data and extracted properties.

.NOTES
- Requires Azure PowerShell module to be installed and authenticated.
- Requires ImportExcel module to be installed for reading Excel files.
- The script assumes the Excel file has specific worksheets named 'All_Assessed_Machines' and 'All_Assessed_Disks'.

#>

param(
[Parameter(Mandatory=$true)] [string]$filePath,
[Parameter(Mandatory = $false)] [string]$outputFile = ".\summary.json" # Json file to export the results to
)

# Start counting individual VM SKUs
# Check if the worksheet 'All_Assessed_Machines' exists in the Excel file
$worksheets = Get-ExcelSheetInfo -Path $filePath
if (-not $worksheets) {
Write-Output "Error accessing the Excel file: No worksheets found or file could not be read."
exit
}
$worksheetExists = $worksheets | Where-Object { $_.Name -eq 'All_Assessed_Machines' }
if ( $worksheetExists) {} else {
Write-Output "Worksheet 'All_Assessed_Machines' not found in the Excel file."
}
# If the worksheet exists, proceed with importing data
# Import the Excel file
$Data = Import-Excel -Path $filePath -WorksheetName 'All_Assessed_Machines' | Group-Object 'Recommended Size' | Sort-Object -Property Count -Descending

# Initialize an empty array for VM SKUs
$VMskus = @()

# Loop through each group and display the recommended VM sizes
foreach ($Group in $Data) {
Write-Output "Recommended Size: $($Group.Name) - Count: $($Group.Count)"
# Add to output object
$VMskus += @{
vmSize = $Group.Name
}
}

# Start counting individual Disk SKUs
# Check if the worksheet 'All_Assessed_Disks' exists in the Excel file
$worksheets = Get-ExcelSheetInfo -Path $filePath
if (-not $worksheets) {
Write-Output "Error accessing the Excel file: No worksheets found or file could not be read."
exit
}
$worksheetExists = $worksheets | Where-Object { $_.Name -eq 'All_Assessed_Disks' }
if ( $worksheetExists) {} else {
Write-Output "Worksheet 'All_Assessed_Disks' not found in the Excel file."
}
# If the worksheet exists, proceed with importing data
# Import the Excel file
$Data = Import-Excel -Path $filePath -WorksheetName 'All_Assessed_Disks' | Group-Object 'Recommended disk size SKU' | Sort-Object -Property Count -Descending

# Initialize an empty array for ResourceSkus
$diskSkus = @()

# Add to output object
foreach ($Group in $Data) {
Write-Output "Recommended Disk Size SKU: $($Group.Name) - Count: $($Group.Count)"
$diskSkus += @{
name = switch -Wildcard ($Group.Name) {
"PremiumV2*" { "PremiumV2_LRS"; break }
"Premium*" { "Premium_LRS"; break }
"StandardSSD*" { "StandardSSD_LRS"; break }
"Standard*" { "Standard_LRS"; break }
"Ultra*" { "UltraSSD_LRS"; break }
default { "Unknown" }
}
tier = $Group.Name -replace "Premium|Standard|Ultra", "" # Extract size from SKU name

}
}

# As long as we don't care about a specific region in the data collection phase, we can use a dummy value
$dummyRegion = "dummyregion"

# Build the final object
$output = @(
    @{
        ResourceCount = $diskSkus.Count
        ResourceType = "microsoft.compute/disks"
        ResourceSkus = $diskSkus
        AzureRegions = @($dummyRegion) # Replace with actual region if needed
    },
@{
ResourceCount = $VMskus.Count
ResourceType = "microsoft.compute/virtualmachines"
ResourceSkus = $VMskus
AzureRegions = @($dummyRegion) # Replace with actual region if needed
}
)

# Convert the output to JSON format
$jsonOutput = $output | ConvertTo-Json -Depth 10
# Save the JSON output to a file
$jsonOutput | Out-File -FilePath $outputFile -Encoding utf8
Write-Output "JSON output saved to $outputFile"
9 changes: 9 additions & 0 deletions docs/wiki/Introduction-to-azure2azure-migration-toolkit.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ This guide describes how to leverage the Azure to Azure migration toolkit when m
The repo at present contains code and details for the following:

- Script and supporting files to collect Azure resource inventory and properties from either an Azure resource group, an Azure subscription (default behavior) or multiple Azure subscriptions. This functionality is contained in the 1-Collect directory.
- Script to convert the output Excel file from a Azure Migrate Assessment to the same format.
- Script to determine service availability in the target region based on the inventory collected in the previous step. This functionality is contained in the 2-AvailabilityCheck directory. Note that this functionality is not yet complete and is a work in progress.

## Prerequisites
Expand All @@ -19,6 +20,7 @@ The repo at present contains code and details for the following:
- Azure Powershell module Az.Monitor 5.2.2 or later
- Azure Powershell module Az.ResourceGraph 1.2.0 or later
- Azure Powershell module Az.Accounts 4.1.0 or later
- Azure Powershell ImportExcel module for Azure Migrate script

## High Level Steps

Expand All @@ -28,6 +30,7 @@ The repo at present contains code and details for the following:
- Navigate to the `1-Collect` directory.
- Logon to Azure with an account that has the required permissions to collect the inventory using `Connect-AzAccount`.
- Run the script `Get-AzureServices.ps1` to collect the Azure resource inventory and properties, for yor relevant scope (resource group, subscription or multiple subscriptions). The script will generate a resources.json and a summary.json file in the same directory. The resources.json file contains the full inventory of resources and their properties, while the summary.json file contains a summary of the resources collected. For examples on how to run the script for different scopes please see 1-Collect scope examples - [1-Collect Scope Examples](#1-collect-scope-examples) below.
- Alternatively you can run `Get-RessourcesFromAM.ps1` against an Azure Migrate `Assessment.xlsx` file to convert the VM & Disk SKUs into the same output as `Get-AzureServices.ps1` to be used further with the `2-AvailabilityCheck/Get-AvailabilityInformation.ps1` script.
- After collecting the inventory, the intent is that you can use the `2-AvailabilityCheck/Get-AvailabilityInformation.ps1` script to check the availability of the services in the target region. This script will generate a services.json file in the same directory, which contains the availability information for the services in the target region. Note that this functionality is not yet complete and is a work in progress.

## 1-Collect Scope Examples
Expand All @@ -49,3 +52,9 @@ Get-AzureServices.ps1 -scopeType subscription -subscriptionId <subscription-id>
```powershell
Get-AzureServices.ps1 -multiSubscription -workloadFile <path-to-workload-file>
```

### 1.1-Azure Migrate Script Examples

```powershell
Get-RessourcesFromAM.ps1 -filePath "C:\path\to\Assessment.xlsx" -outputFile "C:\path\to\summary.json"
```