# PowerShell Script to Check VM Hard Disk Types and Export Results

# Fetch all VMs
$vms = Get-VM

# Initialize variables
$totalVMs = $vms.Count
$completedVMs = 0

# Create an empty array to store results
$results = @()

# Process each VM
foreach ($vm in $vms) {
    # Get hard disks of the current VM
    $hardDisks = Get-HardDisk -VM $vm

    # Filter for thin disks and add results to the array
    $filteredDisks = $hardDisks | Where-Object { $_.DiskType -eq "thin" } | Select-Object @{Name="VMName"; Expression={$vm.Name}}, Name, DiskType
    $results += $filteredDisks

    # Update completed VM count
    $completedVMs++

    # Calculate and show progress
    $progress = [math]::Round(($completedVMs / $totalVMs) * 100, 2)
    Write-Progress -Activity "Checking VM Hard Disks" -Status "$vm.Name ($progress% completed)" -PercentComplete $progress
}

# Export results to CSV
$results | Export-Csv C:\Users\vcapsie\Desktop\thindisks.csv -NoTypeInformation