{"id":3438,"date":"2013-06-07T00:01:00","date_gmt":"2013-06-07T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2013\/06\/07\/build-and-restore-snapshots-in-hyper-v-with-windows-powershell\/"},"modified":"2013-06-07T00:01:00","modified_gmt":"2013-06-07T00:01:00","slug":"build-and-restore-snapshots-in-hyper-v-with-windows-powershell","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/build-and-restore-snapshots-in-hyper-v-with-windows-powershell\/","title":{"rendered":"Build and Restore Snapshots in Hyper-V with Windows PowerShell"},"content":{"rendered":"<p><strong style=\"font-size: 12px\">Summary<\/strong><span style=\"font-size: 12px\">: Microsoft PowerShell MVP, Sean Kearney, talks about using Windows PowerShell to build and restore snapshots in Hyper-V.<\/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;\nWith Microsoft TechEd Europe and a few other presentations on the horizon, I was thinking about how nice it would be have my environments self manage for the demos.\nTypically with most demos in a virtual environment, you make a snapshot of everything in the Gold setup. Then when you enter into your presentations, you can immediately roll back to the original configuration to prepare for your next presentation.\nOr perhaps you&rsquo;re firing up a test environment, and you need to be able to take a snapshot and restore sets of machines to troubleshoot a package issue.\nWith Windows Server 2012 and the new Hyper-V module, this is as natural as breathing.\nLet&rsquo;s say we have a list of virtual machines in our environment: a domain controller, a SQL Server, and perhaps our web application. We&rsquo;ll name them DC1, SQL1, WEB1. Although these are the NetBios names, for convenience I have given them the same names in Hyper-V.<\/p>\n<p style=\"padding-left: 30px\">$VMNames=&rdquo;DC1&rdquo;,&rdquo;SQL1&rdquo;,&rdquo;WEB1&rdquo;\nTo create a checkpoint on the virtual machines, we can simply use the <strong>Checkpoint-VM<\/strong> cmdlet and run it like this:<\/p>\n<p style=\"padding-left: 30px\">CHECKPOINT-VM &ndash;Name DC1 &ndash;Snapshotname &lsquo;Base&rsquo;\nThis will not only create a snapshot, but it will have a unique name that we can refer to. To run this against a list of machines, we can pipe the list by using <strong>Get-VM<\/strong> or supply a list like in our variable:<\/p>\n<p style=\"padding-left: 30px\">$VMNames | GET-VM | CHECKPOINT-VM &ndash;SnapshotName &lsquo;Base&rsquo;<strong><\/strong>\nThis will create a snapshot named &ldquo;Base&rdquo; on the virtual machines named <strong>DC1<\/strong>, <strong>SQL1<\/strong>, and <strong>WEB1<\/strong>.\nIf we&rsquo;d like to access all of these snapshots, we can run this command:<\/p>\n<p style=\"padding-left: 30px\">$VMNames | GET-VM | GET-VMSnapshot &ndash;Name &lsquo;Base&rsquo;\nWe can now take this list and restore them:<\/p>\n<p style=\"padding-left: 30px\">$VMNames | GET-VM | GET-VMSnapshot &ndash;Name &lsquo;Base&rsquo; | RESTORE-VMSnapshot &ndash;confirm:$False\nOne line and now I can restore any demo by using Windows Powershell. With very minor changes, I can create multiple snapshots with unique names by changing the name of snapshot.\nCool, eh?\nFeel the Power within you.\n~Sean<br \/> The Energized Tech\nGreat job, Sean. Join us tomorrow for more cool Windows PowerShell stuff.\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><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Microsoft PowerShell MVP, Sean Kearney, talks about using Windows PowerShell to build and restore snapshots in Hyper-V. 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,45],"class_list":["post-3438","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-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Microsoft PowerShell MVP, Sean Kearney, talks about using Windows PowerShell to build and restore snapshots in Hyper-V. 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\/3438","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=3438"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/3438\/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=3438"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=3438"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=3438"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}