Please use all scripts published by me with caution. The scripts have been tested in my environment and are functional, but I do not take responsibility for how they may behave in your environment.
Scirpt to calculate disk number:
$vmsall = get-vm | where {$_.powerstate -like "PoweredOn"}. ## for all VMs defined here
$vmdisks = @()
foreach ($vv in $vmsall){
$diskforvm = New-Object -TypeName psobject
$diskforvm | Add-Member -MemberType NoteProperty -name "name"-value $vv.name
$diskforvm | Add-Member -MemberType NoteProperty -name "disk_number" -value (($vv | get-view).layoutex.disk.key).count
$vmdisks += $diskforvm
}
$vmdisks | Sort-Object -Property disk_number
Script to check various disk parameters:
#vms contains the list of VMs that we want to work on
foreach ($vm in $vms){
Write-Host "checking:" + $vm
if (-not (get-vm $vm)){
$vm | out-file -Append desktop\disk-size-scope-21062023-notfound.txt}
else{
get-vm $vm | select name, @{n="UsedSpaceGB"; e={[Math]::Ceiling($_.UsedSpaceGB)}},@{n="ProvisionedSpaceGB"; e={[Math]::Ceiling($_.ProvisionedSpaceGB)}}, @{n="DiskSize"; e={(Get-HardDisk -VM $_ | Measure-Object -Sum CapacityGB).Sum}}, @{n="RealUsage"; e={[Math]::Ceiling(((($_ | get-view).guest.disk.Capacity | Measure-Object -Sum).sum / 1GB) - ((($_ | get-view).guest.disk.freespace | measure-object -sum).sum / 1GB))}}, memorygb, @{n="ClusterName"; e={(Get-Cluster -vm $_).name}}, @{n="CPU"; e={cpunum}} | Export-Csv -Append -Path desktop\disk-size-scope-21062023.csv }
}
Script to check Physical or Virtual (Bus Sharing Mode) – indicating RDM:
#vms contains the list of VMs that we want to work on
$array = @()
foreach ($vm in $vms){
$vm = get-vm $vm
$disks = $vm | Get-ScsiController | Where-Object {$_.BusSharingMode -eq 'Physical' -or $_.BusSharingMode -eq 'Virtual'}
foreach ($disk in $disks){
$REPORT = New-Object -TypeName PSObject
$REPORT | Add-Member -type NoteProperty -name Name -Value $vm.Name
$REPORT | Add-Member -type NoteProperty -name VMHost -Value $vm.Host
$REPORT | Add-Member -type NoteProperty -name Mode -Value $disk.BusSharingMode
$REPORT | Add-Member -type NoteProperty -name Type -Value 'BusSharing'
$REPORT | Add-Member -type NoteProperty -name UsedSpacegB -Value [Math]::Ceiling($vm.UsedSpaceGB)
$array += $REPORT
}
}
Similar script but returning more information:
$array = @()
foreach ($vmka in $vms){
$vmka = get-vm -name $vmka
$REPORT = New-Object -TypeName PSObject
$REPORT | Add-Member -type NoteProperty -name Name -Value $vmka.name
$REPORT | Add-Member -type NoteProperty -name noSharingControlerNum -Value ($vmka |Get-ScsiController | where {$_.BusSharingMode -like "NoSharing"}).count
$REPORT | Add-Member -type NoteProperty -name SharedControlerNum -Value ($vmka |Get-ScsiController | where {$_.BusSharingMode -eq 'Physical' -or $_.BusSharingMode -eq 'Virtual'}).count
#hack with -join, otherwise it is not possible to export to csv
$noShareDisks = (Get-HardDisk -VM $vmka | where {$_.extensiondata.controllerkey -in ($vmka |Get-ScsiController | where {$_.BusSharingMode -like "NoSharing"}).key}).Filename -join ", "
$REPORT | Add-Member -type NoteProperty -name noSharedDisks -Value $noShareDisks
$sharedDisks = (Get-HardDisk -VM $vmka | where {$_.extensiondata.controllerkey -in ($vmka |Get-ScsiController | where {$_.BusSharingMode -like 'Physical' -or $_.BusSharingMode -like 'Virtual'}).key}).Filename -join ", "
$REPORT | Add-Member -type NoteProperty -name SharedDisks -Value $sharedDisks
$noShareDisksNum = (Get-HardDisk -VM $vmka | where {$_.extensiondata.controllerkey -in ($vmka |Get-ScsiController | where {$_.BusSharingMode -like "NoSharing"}).key}).count
$REPORT | Add-Member -type NoteProperty -name noSharedDisksNum -Value $noShareDisksNum
$sharedDisksNum = (Get-HardDisk -VM $vmka | where {$_.extensiondata.controllerkey -in ($vmka |Get-ScsiController | where {$_.BusSharingMode -like 'Physical' -or $_.BusSharingMode -like 'Virtual'}).key}).count
$REPORT | Add-Member -type NoteProperty -name SharedDisksNum -Value $sharedDisksNum
$REPORT | Add-Member -type NoteProperty -name noSharedDiskSizeGB -Value ((Get-HardDisk -VM $vmka | where {$_.extensiondata.controllerkey -in ($vmka |Get-ScsiController | where {$_.BusSharingMode -like "NoSharing"}).key}).CapacityGB | Measure-Object -Sum).sum
$REPORT | Add-Member -type NoteProperty -name SharedDisksSizeGB -Value ((Get-HardDisk -VM $vmka | where {$_.extensiondata.controllerkey -in ($vmka |Get-ScsiController | where {$_.BusSharingMode -eq 'Physical' -or $_.BusSharingMode -eq 'Virtual'}).key}).CapacityGB | Measure-Object -Sum).sum
$array += $REPORT
}
Most likely, you would need to modify the scripts to better suit your specific task. Nevertheless, I hope the ones presented above will be helpful.
No Comments