PowerShell scripts to help you out with detailed disk/storage calculations.

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

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Linux
Migrate WordPress site to another hosting service.

IntroductionThis article details the migration of WordPress site (exactly this site you are now on) from one service provider to Amazon Lightsail. There might be various reason to do that (mine is outlined below) but in general I hope to share the message that especially with WordPress, migration can be …

VMware
VMware Workstation and Fusion can be installed and use for free (even for the enterprise)

For a while now, the VMware Workstation (and Fusion for MacOS) can be used without any additional fee for Personal use. That was a great Broadcom news and nice gesture from that software vendor. Recently Broadcom announced that the software will be available for all, even the commercial sector. This …

Linux
Salt, VMware implementation – part 1, introduction

As every IT administrator knows, the infrastructure (meaning storages, compute, VMware virtualisation stack) is just a fundaments to run various operating systems (OS) and finally (containerized) application. Therefore, installation of (let’s call it) infrastructure in the datacenter (SDDC), in that sense is just the beginning of the adventure. No wonder, …