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.

VMware
VCF, backup configuration

Backup implementation for VMware component is fairly easy. Just the requirements is to configure SFTP server in proper way and make it network available to the VMware components. SDDC Manager and NSX Manager backup In VCF Operations it is possible to configure backup for SDDC Manager and NSX Manager. Go …

VMware
VCF Automation, fresh environment configuration with identity providers and access control.

Introduction Login Login as user admin to the Organization name: system or if selected manual: Check the connections (in Administration section), where you should see connection to the vCenter and NSX-t manager as those are provided automatically via VCF Operations: the same for VCF Instances: Also check your networking: Identity …

VMware
VCF SoS

SoS (Supportability and Serviceability) command can be used for troubleshooting purpose to generate VCF (per component) log bundle, massively enable/disable ssh service on ESXi, vCenter, password and certificates expiry status, verify cluster health and many other. while troubleshooting, the following commands can be helpful: