{"id":2018,"date":"2013-08-17T14:58:37","date_gmt":"2013-08-17T14:58:37","guid":{"rendered":"https:\/\/pipe2text.com\/?page_id=2018"},"modified":"2014-02-05T19:21:28","modified_gmt":"2014-02-05T19:21:28","slug":"using-powershell-to-create-a-virtual-machine-inventory-in-vmware-and-export-it-to-a-csv-file","status":"publish","type":"page","link":"https:\/\/pipe2text.com\/?page_id=2018","title":{"rendered":"Using PowerShell to create a Virtual Machine Inventory in VMware and Export it to a CSV File"},"content":{"rendered":"<p>Hi all,<\/p>\n<p>In this blog I will explain an easy way to generate a Virtual Machine inventory\u00a0and export it to\u00a0a csv file. We will be using the \u201cGet-VM\u201d cmdlet and piping it to the \u201cExport-csv\u201d cmdlet to get the information we need in the examples below. To do anything with PowerShell in VMware you will need to install VMware vSphere PowerCLI. You will then need to open PowerCLI connect to your VMWare vCenter server by typing \u201cConnect-VIServer vCenterServerName\u201d.<\/p>\n<p>The simplest way to get a VM inventory with lots of useful information is to type the following command replacing the path with the directory and file name you would like to use.<\/p>\n<p>Get-VM | Export-Csv -path &#8220;<em>c:\\reports\\vminventory.csv<\/em>&#8221; \u2013NoTypeInformation<\/p>\n<p>The command above will dump a list of your VMs to a csv file containing the following fields:<\/p>\n<p>PowerState, Version, Description, Notes, Guest, NumCpu, MemoryMB, MemoryGB, HardDisks, NetworkAdapters, UsbDevices, CDDrives, FloppyDrives, Host, HostId, VMHostId, VMHost, VApp, FolderId, Folder, ResourcePoolId, ResourcePool, PersistentId, UsedSpaceGB, ProvisionedSpaceGB, DatastoreIdList, HARestartPriority, HAIsolationResponse, DrsAutomationLevel, VMSwapfilePolicy, VMResourceConfiguration, Name, CustomFields, ExtensionData, Id, Uid, Client<\/p>\n<p>Now let\u2019s say this you didn\u2019t need this much information in your report. You could type the following command to get the output with only the fields you need. In the following example we will only export the Name, Description, PowerState, NumCpu and MemoryGB fields.<\/p>\n<p>Get-VM | select Name, Description, PowerState, NumCpu, MemoryGB | Export-Csv -path &#8220;<em>c:\\reports\\vminventory.csv<\/em>&#8221; -NoTypeInformation<\/p>\n<p>If you needed to sort the spreadsheet by one of the fields for example the \u201cName\u201d field, you can type the following command:<\/p>\n<p>Get-VM | select Name, Description, PowerState, NumCpu, MemoryGB | sort Name | Export-Csv -path &#8220;<em>c:\\reports\\vminventory.csv<\/em>&#8221; \u2013NoTypeInformation<\/p>\n<p>The example above will create a csv with the Name, Description, PowerState, NumCpu and MemoryGB fields and sort the list by Name in alphabetical order.<\/p>\n<p>I hope this helps. As always, 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 View Datastore and Virtual Machine Space Usage Information in VMware\" href=\"https:\/\/pipe2text.com\/?page_id=2673\">Using PowerShell to View Datastore and Virtual Machine Space Usage Information in VMware<\/a><\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi all, In this blog I will explain an easy way to generate a Virtual Machine inventory\u00a0and export it to\u00a0a csv file. We will be using the \u201cGet-VM\u201d cmdlet and piping it to the \u201cExport-csv\u201d cmdlet to get the information &hellip; <a href=\"https:\/\/pipe2text.com\/?page_id=2018\">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-2018","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/pipe2text.com\/index.php?rest_route=\/wp\/v2\/pages\/2018","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=2018"}],"version-history":[{"count":12,"href":"https:\/\/pipe2text.com\/index.php?rest_route=\/wp\/v2\/pages\/2018\/revisions"}],"predecessor-version":[{"id":2691,"href":"https:\/\/pipe2text.com\/index.php?rest_route=\/wp\/v2\/pages\/2018\/revisions\/2691"}],"wp:attachment":[{"href":"https:\/\/pipe2text.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2018"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}