{"id":3658,"date":"2013-05-10T00:01:00","date_gmt":"2013-05-10T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2013\/05\/10\/get-a-list-of-virtual-machines-by-using-powershell\/"},"modified":"2013-05-10T00:01:00","modified_gmt":"2013-05-10T00:01:00","slug":"get-a-list-of-virtual-machines-by-using-powershell","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/get-a-list-of-virtual-machines-by-using-powershell\/","title":{"rendered":"Get a List of Virtual Machines by Using PowerShell"},"content":{"rendered":"<p><strong style=\"font-size: 12px\">Summary<\/strong><span style=\"font-size: 12px\">: Learn how to use Windows PowerShell&nbsp;3.0 in Windows Server 2012 to obtain a list of virtual machines.<\/span>\nMicrosoft Scripting Guy, Ed Wilson, is here. If you are a seasoned Hey, Scripting Guy! Blog reader, you know that the most frequent guest blogger is Sean Kearney. If you are new to the blog, I welcome you, and I encourage you to catch up with <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/tags\/sean+kearney\/\" target=\"_blank\">Sean&rsquo;s previous blogs<\/a>.\nSean is a Windows PowerShell MVP and <a href=\"http:\/\/blogs.technet.comhttps:\/\/devblogs.microsoft.com\/scripting\/honorary-scripting-guy-award-recipients-announced\/\" target=\"_blank\">an Honorary Scripting Guy.<\/a> Sean has been selected to present sessions called <a href=\"https:\/\/channel9.msdn.com\/Events\/TechEd\/NorthAmerica\/2013\/MDC-B326#fbid=rHDRO4Syj3v\" target=\"_blank\">Integrating with Microsoft System Center 2012 and Windows PowerShell<\/a> at TechEd NA and TechEd Europe this year. In his free time, Sean has written several blog posts about Hyper-V and some other cool stuff, and for the next few weeks, Sean will be the designated guest blogger on Fridays. Take it away Sean&hellip;\nSo you&rsquo;ve got the new Hyper-V environment, and you need to get a list of those virtual machines. Life is smooth and easy&hellip;\nLet&rsquo;s think about this, you want to &ldquo;get&rdquo; a &ldquo;virtual machine&rdquo; list. Would anybody like to guess just how easy this one is?\nIn Windows Server 2012 with the built-in Hyper-V, all&nbsp;you need to run is:<\/p>\n<p style=\"padding-left: 30px\">Get-VM\nThis will output a list of virtual machines and their current state to the Windows PowerShell console.\nIf you&rsquo;d like to filter and show only virtual machines that are currently in the running state, you can apply this command in the console:<\/p>\n<p style=\"padding-left: 30px\">Get-VM | Where { $_.State&nbsp;&ndash;eq &lsquo;Running&rsquo; }\nWe can use this and save the state of those workstations:<\/p>\n<p style=\"padding-left: 30px\">Get-VM | Where { $_.State&nbsp;&ndash;eq &lsquo;Running&rsquo; } | Save-VM\nThis provides the same result as if you go into the Hyper-V console, right-click &nbsp;the names of individual workstations, and click <strong>Save<\/strong>.\nIf you have administrative credentials, you can even manage remote workstations running Windows Server 2012 with Hyper-V in this manner:<\/p>\n<p style=\"padding-left: 30px\">Get-VM&nbsp;&ndash;computername &lsquo;Contoso-HyperV-1&rsquo; | Where { $_.State&nbsp;&ndash;eq &lsquo;Running&rsquo; } | Save-VM\nWith this, you can also use our good friend <strong>Export-CSV<\/strong> to produce a file with the list of virtual machines:<\/p>\n<p style=\"padding-left: 30px\">Get-VM&nbsp;&ndash;computername &lsquo;Contos-HyperV-1&rsquo; | EXPORT-CSV C:PowershellVMlist.csv\nThe best part is that not only are these cmdlets built in, but they operate in the free Hyper-V Server 2012. There&rsquo;s more of course, but let&rsquo;s take one piece at a time&hellip;&nbsp;&nbsp;\nFeel the Power within you.\n~Sean<br \/> The Energized Tech\nThanks, Sean. Sean will be running a weekly series about Hyper-V and Windows PowerShell for the next several months. Join him next Friday, and join me tomorrow for more Windows PowerShell goodness.\nI invite you to follow me on <a href=\"http:\/\/bit.ly\/scriptingguystwitter\" target=\"_blank\">Twitter<\/a> and <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\" target=\"_blank\">Facebook<\/a>. If you have any questions, send email to me at <a href=\"http:\/\/blogs.technet.commailto:scripter@microsoft.com\" target=\"_blank\">scripter@microsoft.com<\/a>, or post your questions on the <a href=\"http:\/\/bit.ly\/scriptingforum\" target=\"_blank\">Official Scripting Guys Forum<\/a>. See you tomorrow. Until then, peace.\n<strong>Ed Wilson, Microsoft Scripting Guy<\/strong><span style=\"font-size: 12px\">&nbsp;<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Learn how to use Windows PowerShell&nbsp;3.0 in Windows Server 2012 to obtain a list of virtual machines. Microsoft Scripting Guy, Ed Wilson, is here. If you are a seasoned Hey, Scripting Guy! Blog reader, you know that the most frequent guest blogger is Sean Kearney. If you are new to the blog, I welcome [&hellip;]<\/p>\n","protected":false},"author":596,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[56,271,3,154,130,45,368],"class_list":["post-3658","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-guest-blogger","tag-hyper-v","tag-scripting-guy","tag-sean-kearney","tag-servers","tag-windows-powershell","tag-windows-server-2012"],"acf":[],"blog_post_summary":"<p>Summary: Learn how to use Windows PowerShell&nbsp;3.0 in Windows Server 2012 to obtain a list of virtual machines. Microsoft Scripting Guy, Ed Wilson, is here. If you are a seasoned Hey, Scripting Guy! Blog reader, you know that the most frequent guest blogger is Sean Kearney. If you are new to the blog, I welcome [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/3658","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/596"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=3658"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/3658\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=3658"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=3658"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=3658"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}