How to monitor Azure resources
# Connect to Azure
Connect-AzAccount
# Function to get disk details
function Get-DiskDetails {
param (
[Parameter(Mandatory=$true)]
[string]$ManagedDiskId
)
$diskName = (Get-AzResource -ResourceId $ManagedDiskId).Name
$resourceGroup = (Get-AzResource -ResourceId $ManagedDiskId).ResourceGroupName
$disk = Get-AzDisk -ResourceGroupName $resourceGroup -DiskName $diskName
return $disk
}
# Output file path
$outputFilePath = "C:\Path\to\output.html"
# Start HTML file content
$htmlContent = @"
<!DOCTYPE html>
<html>
<head>
<style>
table {
font-family: Arial, sans-serif;
border-collapse: collapse;
width: 100%;
}
td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
th {
background-color: #dddddd;
}
</style>
</head>
<body>
"@
# Get all VMs
$vms = Get-AzVM
# Add table headers to HTML content
$htmlContent += "<table>"
$htmlContent += "<tr>"
$htmlContent += "<th>VM Name</th>"
$htmlContent += "<th>Power State</th>"
$htmlContent += "<th>Disk Name</th>"
$htmlContent += "<th>Disk Size (GB)</th>"
$htmlContent += "<th>Storage Type</th>"
$htmlContent += "</tr>"
# Iterate through VMs
foreach ($vm in $vms) {
$vmName = $vm.Name
$resourceGroupName = $vm.ResourceGroupName
# Get VM power state
$vmPowerState = $vm.PowerState
# Get VM disks
$disks = $vm.StorageProfile.DataDisks
# Iterate through disks
foreach ($disk in $disks) {
$diskName = $disk.Name
$managedDiskId = $disk.ManagedDisk.Id
# Get disk details
$diskDetails = Get-DiskDetails -ManagedDiskId $managedDiskId
$diskSizeGB = $diskDetails.DiskSizeGB
$diskType = $diskDetails.Sku.Name
# Add VM and disk details to HTML content
$htmlContent += "<tr>"
$htmlContent += "<td>$vmName</td>"
$htmlContent += "<td>$vmPowerState</td>"
$htmlContent += "<td>$diskName</td>"
$htmlContent += "<td>$diskSizeGB</td>"
$htmlContent += "<td>$diskType</td>"
$htmlContent += "</tr>"
}
}
# End HTML file content
$htmlContent += "</table>"
$htmlContent += "</body></html>"
# Save content to HTML file
$htmlContent | Out-File -FilePath $outputFilePath -Encoding UTF8
Write-Host "HTML file generated successfully: $outputFilePath"
Comments
Post a Comment