{"id":674,"date":"2021-04-25T19:48:27","date_gmt":"2021-04-25T18:48:27","guid":{"rendered":"http:\/\/192.168.8.14\/?p=674"},"modified":"2021-04-25T20:21:16","modified_gmt":"2021-04-25T19:21:16","slug":"vm-disk-info-script","status":"publish","type":"post","link":"https:\/\/www.jasonstreet.com\/?p=674","title":{"rendered":"VM disk info script"},"content":{"rendered":"\n<p>Recently I was trouble shooting a Zerto issue that occurred due to a storage &#8220;blip&#8221;. Some Zerto Z-VRAHs had lost disks and many VPGs where in an error state. One of the shadow Z-VRAs had lost its 4 &#8220;OS&#8221; disks. These disks are copied from the ZVM and are device 0 on SCSI busses 0-3. Easley fixed once once identified but how many other Z-VRAHs where the with one or more missing &#8220;OS&#8221; disks?<\/p>\n\n\n\n<p>So, here is a quick script I put together to get the SCSI bus, device number and a couple of other bits of VM hard drive info. Later Ill expand the script to detect thick\/thin provisioned disks and used size.<\/p>\n\n\n\n<p>When run you will get an array called report that will look something like this.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>VM name<\/li><li>The disk name as shown in the VM settings<\/li><li>Path to the VMDK<\/li><li>SCSI bus number<\/li><li>SCSI device\/unit ID<\/li><li>Disk Size in Kbytes, This is the capacity not the actual size of the VMDK <\/li><li>Controller key<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"802\" height=\"134\" src=\"http:\/\/192.168.8.14\/wp-content\/uploads\/2021\/04\/DiskReporter01.png\" alt=\"\" class=\"wp-image-675\" srcset=\"https:\/\/www.jasonstreet.com\/wp-content\/uploads\/2021\/04\/DiskReporter01.png 802w, https:\/\/www.jasonstreet.com\/wp-content\/uploads\/2021\/04\/DiskReporter01-300x50.png 300w, https:\/\/www.jasonstreet.com\/wp-content\/uploads\/2021\/04\/DiskReporter01-768x128.png 768w\" sizes=\"auto, (max-width: 802px) 100vw, 802px\" \/><\/figure>\n\n\n\n<p>Here is the script.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\n$VMs = get-VM jason*  # enter the name \/ part of name \/ or just use get-vm for everything\n\n\n$Report = @()\nforeach ($VM in $VMs)\n{\n    # get the HDs on the VM so we can loop though each one.\n    $HDs = $vm | get-harddisk \n    foreach ($HD in $HDs)\n    {\n        # match this HD to the HW device info in the VM.ExtensionData object list\n        $CKey = $hd.ExtensionData.ControllerKey\n        $Device = $vm.Extensiondata.Config.Hardware.Device | where{$_.Key -eq $CKey}\n\n        # create a temp object for each HD\n        $tmpDiskObj = &#039;&#039; | select VM,Disk,Path,SCSIBus,SCSIUnit,CapacityKB,cKey\n        $tmpDiskObj.VM = $VM.name\n        $tmpDiskObj.Disk = $HD.Name\n        $tmpDiskObj.SCSIBus = $Device.BusNumber\n        $tmpDiskObj.SCSIUnit = $hd.ExtensionData.UnitNumber\n        $tmpDiskObj.Path = $HD.FileName\n        $tmpDiskObj.CapacityKB= $HD.CapacityKB\n        $tmpDiskObj.cKey = $CKey\n        $Report += $tmpDiskObj\n    }\n}\n\n$Report | ft\n<\/pre><\/div>\n\n\n<p>Hope that is some use to some one.<\/p>\n\n\n\n<p>If it helps. Here is that same code but as a function.<\/p>\n\n\n\n<p>To call the function use this<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>$VMs | Get-VMDiskInfo<\/li><li>Get-VMDiskInfo -VM $VMs<\/li><li>&#8220;MyVMName&#8221; | Get-VMDiskInfo<\/li><li>Get-VMDiskInfo | -VM &#8220;MyVMName&#8221;<\/li><\/ul>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\nfunction Get-VMDiskInfo \n{\n   &#x5B;CmdletBinding()]\n    param(\n        &#x5B;Parameter(ValueFromPipeline=$true)] $VM\n\n    )\n    if ($VM -is &#x5B;string]){$VMs = get-vm $VM -ErrorAction SilentlyContinue}\n    if ($VM -is &#x5B;VMware.VimAutomation.ViCore.Impl.V1.VM.UniversalVirtualMachineImpl]){$VMs = $VM}\n\n    if ($VMs)\n    {\n        $Report = @()\n        foreach ($VM in $VMs)\n        {\n            # get the HDs on the VM so we can loop though each one.\n            $HDs = $vm | get-harddisk \n            foreach ($HD in $HDs)\n            {\n                # match this HD to the HW device info in the VM.ExtensionData object list\n                $CKey = $hd.ExtensionData.ControllerKey\n                $Device = $vm.Extensiondata.Config.Hardware.Device | where{$_.Key -eq $CKey}\n\n                # create a temp object for each HD\n                $tmpDiskObj = &#039;&#039; | select VM,Disk,Path,SCSIBus,SCSIUnit,CapacityKB,cKey\n                $tmpDiskObj.VM = $VM.name\n                $tmpDiskObj.Disk = $HD.Name\n                $tmpDiskObj.SCSIBus = $Device.BusNumber\n                $tmpDiskObj.SCSIUnit = $hd.ExtensionData.UnitNumber\n                $tmpDiskObj.Path = $HD.FileName\n                $tmpDiskObj.CapacityKB= $HD.CapacityKB\n                $tmpDiskObj.cKey = $CKey\n                $Report += $tmpDiskObj\n            }\n        }\n        Return $Report\n    }else{\n        Write-Host &quot;No VMs found&quot; -ForegroundColor Red\n        Return $null\n    }\n}\n<\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>Recently I was trouble shooting a Zerto issue that occurred due to a storage &#8220;blip&#8221;. Some Zerto Z-VRAHs had lost disks and many VPGs where in an error state. One of the shadow Z-VRAs had lost its 4 &#8220;OS&#8221; disks. These disks are copied from the ZVM and are device 0 on SCSI busses 0-3&#8230;.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[5,132,43],"tags":[68,10,134,8],"class_list":["post-674","post","type-post","status-publish","format-standard","hentry","category-powercli","category-reporting","category-vmware","tag-disk","tag-report","tag-scsi","tag-vm"],"_links":{"self":[{"href":"https:\/\/www.jasonstreet.com\/index.php?rest_route=\/wp\/v2\/posts\/674","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jasonstreet.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jasonstreet.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jasonstreet.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jasonstreet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=674"}],"version-history":[{"count":5,"href":"https:\/\/www.jasonstreet.com\/index.php?rest_route=\/wp\/v2\/posts\/674\/revisions"}],"predecessor-version":[{"id":680,"href":"https:\/\/www.jasonstreet.com\/index.php?rest_route=\/wp\/v2\/posts\/674\/revisions\/680"}],"wp:attachment":[{"href":"https:\/\/www.jasonstreet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=674"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jasonstreet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=674"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jasonstreet.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=674"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}