{"id":2673,"date":"2014-02-05T19:11:53","date_gmt":"2014-02-05T19:11:53","guid":{"rendered":"https:\/\/pipe2text.com\/?page_id=2673"},"modified":"2014-02-05T21:15:46","modified_gmt":"2014-02-05T21:15:46","slug":"using-powershell-to-view-datastore-and-virtual-machine-space-usage-information-in-vmware","status":"publish","type":"page","link":"https:\/\/pipe2text.com\/?page_id=2673","title":{"rendered":"Using PowerShell to View Datastore and Virtual Machine Space Usage Information in VMware"},"content":{"rendered":"<p>Hi All,<\/p>\n<p>There may be times when you need to view VMware datastore usage information such as capacity, free space, or how much space each virtual machine is using. In this article I will demonstrate how to gather this information formatted and listed on your screen or in a csv file. This will save you from having to spend all day obtaining this information from the vCenter client manually. To do anything with PowerShell in VMware you will need to install VMware vSphere PowerCLI. You will then need to open PowerCLI and connect to your VMWare vCenter server by typing \u201cConnect-VIServer vCenterServerName\u201d.<\/p>\n<p>To start, I will show you how to get list of the VMware Datastores themselves using the \u201cGet-Datastore\u201d cmdlet. To start, simply type the following command and press \u201cEnter\u201d:<\/p>\n<p>Get-Datastore<\/p>\n<p>This command above will list all datastores giving you the free space and capacity for each. The output will look similar to the following information:<\/p>\n<address>Name\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 FreeSpaceGB\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 CapacityGB<\/address>\n<address>\u00a0&#8212;-\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0&#8212;&#8212;&#8212;&#8211;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&#8212;&#8212;&#8212;-<\/address>\n<address>DATASTORE1\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 6.618\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0850.000<\/address>\n<address>DATASTORE2\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 88.378\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 850.000<\/address>\n<address>DATASTORE3\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 126.165\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0850.000<\/address>\n<address>DATASTORE4\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a071.557\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 850.000<\/address>\n<address>\u00a0<\/address>\n<p>Now that we have a list of datastores, we want to see how much space each virtual machine on a particular datastore is using. In the following example I use the \u201cGet-Datastore\u201d cmdlet and pipe it to the \u201cGet-VM\u201d cmdlet to see how much space on DATASTORE1 each virtual machine is using. Type the following command replacing DATASTORE1 with the name of your datastore.<\/p>\n<p>Get-Datastore DATASTORE1 | Get-VM | select name,usedspacegb<\/p>\n<p>The above command will list the name of each virtual machine and the used space for each in gigabytes.<\/p>\n<p>If you would like to get a list of all the properties you can select in addition to or instead of \u201cname\u201d and \u201cusedspacegb\u201d you can use can pipe it to the Get-Member cmdlet to list them. Type the following command replacing DATASTORE1 with the name of your datastore.<\/p>\n<p>Get-Datastore DATASTORE1 | Get-VM | Get-Member<\/p>\n<p>Next, I would like to export this data to a csv file for later review. In the following command I will export the space info to a csv file name datastore.csv located in the c:\\output directory.<\/p>\n<p>Get-Datastore DATASTORE1 | Get-VM | select name,usedspacegb | Export-Csv c:\\output\\datastore.csv -NoTypeInformation<\/p>\n<p>Lastly, if I wanted to export all the Virtual Machines properties for a particular datastore I could type the following command:<\/p>\n<p>Get-Datastore DATASTORE1 | Get-VM | Export-Csv c:\\output\\datastore.csv -NoTypeInformation<\/p>\n<p>For information on creating a full virtual machine inventory in VMware, please my other article <a title=\"Using PowerShell to create a Virtual Machine Inventory in VMware and Export it to a CSV File\" href=\"https:\/\/pipe2text.com\/?page_id=2018\">Using PowerShell to create a Virtual Machine Inventory in VMware and Export it to a CSV File<\/a>.<\/p>\n<p>Hope this helps. For more information out the \u201cGet-Datastore\u201d cmdlet and the \u201cGet-VM\u201d cmdlets, you can simply type \u201cGet-Help Get-Datastore\u201d or \u201cGet-Help Get-VM\u201d. If you have any questions or feedback, please leave a comment.<\/p>\n<p>Related Links:<\/p>\n<p><strong><a title=\"Using PowerShell to get a list Virtual Machine Snapshots in VMware ESXi 4.1\" href=\"https:\/\/pipe2text.com\/?page_id=251\">Using PowerShell to get a list Virtual Machine Snapshots in VMware ESXi 4.1<\/a><\/strong><\/p>\n<p><a title=\"Using PowerShell to Gracefully Shut Down Multiple Virtual Machines in VMware\" href=\"https:\/\/pipe2text.com\/?page_id=1889\"><strong>Using PowerShell to Gracefully Shut Down Multiple Virtual Machines in VMware<\/strong><\/a><\/p>\n<p><a title=\"Using PowerShell to Remove Virtual Machine Snapshots in VMware ESXi 4.1\" href=\"https:\/\/pipe2text.com\/?page_id=1953\"><b>Using PowerShell to Remove Virtual Machine Snapshots in VMware ESXi 4.1<\/b><\/a><\/p>\n<p><strong><a title=\"Using PowerShell to create a Virtual Machine Inventory in VMware and Export it to a CSV File\" href=\"https:\/\/pipe2text.com\/?page_id=2018\">Using PowerShell to create a Virtual Machine Inventory in VMware and Export it to a CSV File<\/a><\/strong><\/p>\n<p><a title=\"Using PowerShell to Take Virtual Machine Snapshots in VMware\" href=\"https:\/\/pipe2text.com\/?page_id=2286\"><strong>Using PowerShell to\u00a0Create Virtual Machine Snapshots in VMware<\/strong><\/a><\/p>\n<p><strong><a title=\"Using PowerShell to View  Virtual Machine Disks (VMDK) Information in VMware and Export to a CSV File\" href=\"https:\/\/pipe2text.com\/?page_id=2635\">Using PowerShell to View\u00a0 Virtual Machine Disks (VMDK) Information in VMware and Export to a CSV File<\/a><\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi All, There may be times when you need to view VMware datastore usage information such as capacity, free space, or how much space each virtual machine is using. In this article I will demonstrate how to gather this information &hellip; <a href=\"https:\/\/pipe2text.com\/?page_id=2673\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"open","ping_status":"open","template":"","meta":{"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","footnotes":""},"class_list":["post-2673","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/pipe2text.com\/index.php?rest_route=\/wp\/v2\/pages\/2673","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pipe2text.com\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/pipe2text.com\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/pipe2text.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/pipe2text.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2673"}],"version-history":[{"count":12,"href":"https:\/\/pipe2text.com\/index.php?rest_route=\/wp\/v2\/pages\/2673\/revisions"}],"predecessor-version":[{"id":2695,"href":"https:\/\/pipe2text.com\/index.php?rest_route=\/wp\/v2\/pages\/2673\/revisions\/2695"}],"wp:attachment":[{"href":"https:\/\/pipe2text.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2673"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}