<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://hypervoria.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Search results matching tag 'Scripts'</title><link>http://hypervoria.com/search/SearchResults.aspx?o=DateDescending&amp;tag=Scripts&amp;orTags=0</link><description>Search results matching tag 'Scripts'</description><dc:language>en-US</dc:language><generator>CommunityServer 2008 SP1 (Build: 30619.63)</generator><item><title>Script: Creating an internal virtual network with Hyper-V</title><link>http://hypervoria.com/hyper-v/script-creating-an-internal-virtual-network-with-hyper-v.aspx</link><pubDate>Mon, 23 Feb 2009 11:44:00 GMT</pubDate><guid isPermaLink="false">813e2024-6b0a-4879-b378-ec7112fe0781:453</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;[excerpt]Ben Armstrong: Moving on from yesterdays script (which showed you how to create a private virtual network) let&amp;rsquo;s look at creating an internal virtual network via a script.&amp;nbsp; An internal virtual network is one that is not connected to a physical network adapter &amp;ndash; but allows virtual machines to communicate with each other and the parent partition.&amp;nbsp; This is a fair bit more complicated than creating a private virtual network:&lt;/p&gt;
&lt;p&gt;[/excerpt]&lt;/p&gt;</description></item><item><title>Script: Creating a private virtual network with Hyper-V</title><link>http://hypervoria.com/hyper-v/script-creating-a-private-virtual-network-with-hyper-v.aspx</link><pubDate>Mon, 23 Feb 2009 11:17:00 GMT</pubDate><guid isPermaLink="false">813e2024-6b0a-4879-b378-ec7112fe0781:448</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;[excerpt]Ben Armstrong: I spent a bunch of time scripting virtual networks under Hyper-V over the weekend &amp;ndash; so this week I am going to share some of my scripts.&amp;nbsp; The first one is a simple one: it creates a private &amp;ndash; or &amp;ldquo;virtual machine only&amp;rdquo; &amp;ndash; virtual network.&lt;/p&gt;
&lt;p&gt;[/excerpt]&lt;/p&gt;</description></item><item><title>Delegation Model in Hyper-V – Part 6</title><link>http://hypervoria.com/hyper-v/delegation-model-in-hyper-v-part-6.aspx</link><pubDate>Sat, 09 Aug 2008 09:27:00 GMT</pubDate><guid isPermaLink="false">813e2024-6b0a-4879-b378-ec7112fe0781:188</guid><dc:creator>bink</dc:creator><description>&lt;p&gt;In previous posts, I have shown how to create Azman scopes and roles to delegate administration of Hyper-V virtual machines to domain users. Now that we have an AzMan scope, let&amp;rsquo;s see how you can apply it to a virtual machine or set of virtual machines. &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt;&amp;nbsp; In Hyper-V, there is no GUI interface to assign a scope to a VM, you need to use the Hyper-V WMI API &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;In my example scenario, I have a set of VMs prefixed with &amp;ldquo;01_&amp;rdquo;and I want to delegate administration of those VMs to Student01 and only this account can view those VMs in Hyper-V mmc console. In Prt 4 and Part 5, I already created a scope called 01_Scope and some role definitions. Let&amp;rsquo;s apply this cope to 01_ VMs. &lt;/p&gt;
&lt;p&gt;&amp;nbsp; &lt;/p&gt;
&lt;h4&gt;&lt;/h4&gt;
&lt;h4&gt;Script&lt;/h4&gt;
&lt;p&gt;$VM_Service = get-wmiobject -namespace root\virtualization Msvm_VirtualSystemManagementService &lt;/p&gt;
&lt;p&gt;$ListofVMs =get-wmiobject -namespace root\virtualization Msvm_ComputerSystem -filter&amp;nbsp; &amp;quot;ElementName &amp;lt;&amp;gt; Name &amp;quot;&amp;nbsp; | `&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; where { $_.ElementName -like &amp;quot;01_*&amp;quot;} &lt;/p&gt;
&lt;p&gt;foreach ($VM in $ListofVMs) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if ( $VM -ne $Null)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $VMGlobalSetting = get-wmiobject -namespace root\virtualization Msvm_VirtualSystemGlobalSettingData | where `&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; { $_.ElementName -like &amp;quot;*$($VM.ElementName)*&amp;quot; }&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $VMGlobalSetting.ScopeOfResidence = &amp;ldquo;01_Scope&amp;rdquo; &lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;$VM_Service.ModifyVirtualSystem($VM.__PATH, $VMGlobalSetting.psbase.Gettext(1))&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;} &lt;/p&gt;
&lt;p&gt;Full Story At Source&lt;/p&gt;</description></item><item><title>Technet 2008 Video:Hyper-V: Scripting &amp;amp; Programmatic Management for Fun &amp;amp; Profit (VBS &amp;amp; PowerShell)</title><link>http://hypervoria.com/hyper-v/technet-2008-video-hyper-v-scripting-amp-programmatic-management-for-fun-amp-profit-vbs-amp-powershell.aspx</link><pubDate>Wed, 06 Aug 2008 08:03:00 GMT</pubDate><guid isPermaLink="false">813e2024-6b0a-4879-b378-ec7112fe0781:254</guid><dc:creator>bink</dc:creator><description>&lt;p&gt;&lt;img src="https://www.microsoft.com/emea/spotlight/images/en/common/header_spotlight.jpg" alt="" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://microsofttech.fr.edgesuite.net/msexp/download/spotlight/998/998_pres.zip"&gt;&lt;img border="0" width="55" src="http://www.microsoft.com/emea/spotlight/images/en/common/download_ppt.jpg" height="75" style="border:0;" alt="" /&gt;&lt;/a&gt;&amp;nbsp;&lt;a href="http://microsofttech.fr.edgesuite.net/msexp/download/spotlight/998/998_high.zip"&gt;&lt;img border="0" width="55" src="http://www.microsoft.com/emea/spotlight/images/en/common/download_video.jpg" height="75" style="border:0;" alt="" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Or view online at source&lt;/p&gt;</description></item><item><title>Invoking diskshadow to back up a Virtual Machine from a Hyper-V Host </title><link>http://hypervoria.com/hyper-v/invoking-diskshadow-to-back-up-a-virtual-machine-from-a-hyper-v-host.aspx</link><pubDate>Wed, 30 Jul 2008 12:09:00 GMT</pubDate><guid isPermaLink="false">813e2024-6b0a-4879-b378-ec7112fe0781:243</guid><dc:creator>bink</dc:creator><description>&lt;p&gt;DiskShadow.exe is a new tool that shipped with Windows Server 2008 and it allows you to create and restore shadow copies (snapshots).&lt;/p&gt;
&lt;p&gt;The tool is similar to vshadow (a free tool that ships with the Volume Shadow Copy/VSS SDK), but it has a diskpart-like interface.&lt;/p&gt;
&lt;p&gt;You can invoke DiskShadow from a cmdline, or you can pass a script to it using the command &amp;quot;diskshadow -s script.txt&amp;quot;&lt;/p&gt;
&lt;p&gt;Below, i will show you an example script to back up all VMs of a Hyper-V Host. First, we need to know the ID of the VSS writer for Hyper-V. To do that you need to invoke the command &amp;quot;list writers&amp;quot; from diskshadow (or from vssadmin). Once you parse its content, look for this GUID as per below underlined text.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; * WRITER &amp;quot;Microsoft Hyper-V VSS Writer&amp;quot;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; - Writer ID&amp;nbsp;&amp;nbsp; =&lt;strong&gt;&lt;span style="text-decoration:underline;"&gt;&lt;em&gt; {66841cd4-6ded-4f4b-8f17-fd23f8ddc3de}&lt;br /&gt;&lt;/em&gt;&lt;/span&gt;&lt;/strong&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; - Writer instance ID = {d49be452-e26e-4255-a723-bfb9f996e703}&lt;/p&gt;
&lt;p&gt;Once you know the ID, you can use&amp;nbsp;a script like one below to create a snapshot for the volume the VM resides on and ensure that the VSS writer for Hyper-V is included in the snapshot process.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;lt;&amp;lt;&lt;/p&gt;
&lt;p&gt;# DiskShadow script file to backup a single VM from a Hyper-V host&lt;br /&gt;set context persistent&lt;/p&gt;
&lt;p&gt;# make sure the path already exists&lt;br /&gt;set metadata c:\example.cab&lt;br /&gt;set verbose on&lt;/p&gt;
&lt;p&gt;begin backup&lt;br /&gt;add volume d: alias SystemAndDataVolumeShadow&lt;/p&gt;
&lt;p&gt;# verify the &amp;quot;Microsoft Hyper-V VSS Writer&amp;quot; writer will be included in the snapshot&lt;br /&gt;writer verify {66841cd4-6ded-4f4b-8f17-fd23f8ddc3de}&lt;br /&gt;create&lt;/p&gt;
&lt;p&gt;end backup&lt;br /&gt;&amp;gt;&amp;gt;&lt;/p&gt;
&lt;p&gt;As you run this, you will see that the Hyper-V VSS writer is included in the shadow copy process and is participating in the backup (other writers might be included too since I chose a writer-involved snapshot and those writers might have data on the volumes selected for backup). Once the snapshot is complete, you can mount the snapshot to a mount point (you can do this using the expose diskshadow command)&amp;nbsp;and copy the entire configuration for the VM to a backup location. You can see which files comprise this VM by looking at the metadata created in the CAB file (look into manifest.xml to see which XML file corresponds for the Hyper-V writer and you can get the specific writer metadata there).&lt;/p&gt;</description></item><item><title>Hyper-V WMI: Creating a Thumbnail Image </title><link>http://hypervoria.com/hyper-v/hyper-v-wmi-creating-a-thumbnail-image.aspx</link><pubDate>Tue, 29 Jul 2008 15:35:00 GMT</pubDate><guid isPermaLink="false">813e2024-6b0a-4879-b378-ec7112fe0781:233</guid><dc:creator>bink</dc:creator><description>&lt;p&gt;Hyper-V has a WMI API that will allow you to create a thumbnail image of any running or paused virtual machine.&amp;nbsp; You can create any sized thumbnail you want (640x480, 800x600, 1024x768 etc&amp;hellip;).&amp;nbsp; Creating the image is pretty easy, you just call GetVirtualSystemThumbnailImage passing a reference to an Msvm_VirutalSystemSettingData instance and the size of the image you want&amp;hellip;&amp;nbsp; However getting something useful from the returned data is a bit tricky&amp;hellip;&amp;nbsp; You get an array of unit8&amp;rsquo;s that represent pixels, the API doesn&amp;rsquo;t have much choice and luckily Powershell makes this not an impossible feat.&amp;nbsp; All you have to do is create a new bitmap object and read (marshal) the pixel data into the object&amp;hellip;&amp;nbsp; So here&amp;rsquo;s a script for you!&lt;/p&gt;
&lt;p&gt;
&lt;table cellspacing="2"&gt;

&lt;tr&gt;
&lt;td valign="top"&gt;&lt;a href="http://blogs.msdn.com/blogfiles/taylorb/WindowsLiveWriter/HyperVWMICreatingaThumbnailImage_CB5C/Windows%20Server%202008%20-%20x64_running_2.jpg"&gt;&lt;img border="0" width="330" src="http://blogs.msdn.com/blogfiles/taylorb/WindowsLiveWriter/HyperVWMICreatingaThumbnailImage_CB5C/Windows%20Server%202008%20-%20x64_running_thumb.jpg" alt="Windows Server 2008 - x64_running" height="248" style="border-width:0px;" title="Windows Server 2008 - x64_running" /&gt;&lt;/a&gt; &lt;/td&gt;
&lt;td valign="top"&gt;&lt;a href="http://blogs.msdn.com/blogfiles/taylorb/WindowsLiveWriter/HyperVWMICreatingaThumbnailImage_CB5C/Windows%20Server%202008%20-%20x64_saved_2.jpg"&gt;&lt;img border="0" width="327" src="http://blogs.msdn.com/blogfiles/taylorb/WindowsLiveWriter/HyperVWMICreatingaThumbnailImage_CB5C/Windows%20Server%202008%20-%20x64_saved_thumb.jpg" alt="Windows Server 2008 - x64_saved" height="246" style="border-width:0px;" title="Windows Server 2008 - x64_saved" /&gt;&lt;/a&gt; &lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top"&gt;&lt;strong&gt;Running Virtual Machine&lt;/strong&gt;&lt;/td&gt;
&lt;td valign="top"&gt;&lt;strong&gt;Saved Virtual Machine&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;

&lt;/table&gt;
&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Continue At Source for the Powershell script&lt;/p&gt;</description></item><item><title>Volume GUIDs - Ways To View/Access The Files Within</title><link>http://hypervoria.com/hyper-v/volume-guids-ways-to-view-access-the-files-within.aspx</link><pubDate>Thu, 24 Jul 2008 02:35:00 GMT</pubDate><guid isPermaLink="false">813e2024-6b0a-4879-b378-ec7112fe0781:191</guid><dc:creator>mcshinsky</dc:creator><description>&lt;p&gt;I&amp;nbsp;have been working with Volume GUIDs more and more in our Hyper-V implementation and there has been a little bit of a learning curve in viewing, modifying, deleting etc... the files that now live on this volume without a drive letter.&amp;nbsp; I haven&amp;#39;t seen much out there on how to manage Volume GUIDs so I thought it would be a good topic for the blog.&amp;nbsp; &lt;/p&gt;
&lt;p&gt;I have to plug &lt;a target="_blank" href="http://blogs.msdn.com/adamfazio/"&gt;&lt;span style="color:#006629;"&gt;Adam Fazio&lt;/span&gt;&lt;/a&gt; for leading to some of the info I have gained on this topic. &lt;/p&gt;
&lt;p&gt;Like a normal volume, with a drive letter, there are 2 ways to view, modify, copy etc... files that reside therein. Explore in the GUI and Command line access. &lt;/p&gt;
&lt;p&gt;Continue At Source&lt;/p&gt;</description></item><item><title>Speeding Up PowerShell Startup</title><link>http://hypervoria.com/hyper-v/speeding-up-powershell-startup.aspx</link><pubDate>Wed, 23 Jul 2008 07:32:00 GMT</pubDate><guid isPermaLink="false">813e2024-6b0a-4879-b378-ec7112fe0781:175</guid><dc:creator>bink</dc:creator><description>&lt;p&gt;&lt;em&gt;Jeffrey Snover [MSFT]:&lt;/em&gt; In V1, we had a&amp;nbsp;problem which caused our assemblies to not get ngen&amp;#39;ed during installation.&amp;nbsp; If you don&amp;#39;t know what &amp;quot;ngen&amp;quot; is, don&amp;#39;t worry - you don&amp;#39;t need to.&amp;nbsp; All you need to know is that we didn&amp;#39;t do the step that makes things go fast on your machine.&amp;nbsp; The instructions for how to fix this:&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:10pt;font-family:Courier New;"&gt;Set-Alias ngen @(&lt;br /&gt;dir (join-path ${env:\windir} &amp;quot;Microsoft.NET\Framework&amp;quot;) ngen.exe -recurse |&lt;br /&gt;sort -descending lastwritetime&lt;br /&gt;)[0].fullName&lt;br /&gt;[appdomain]::currentdomain.getassemblies() | %{ngen $_.location}&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;See discussion &lt;a href="http://blogs.msdn.com/powershell/archive/2007/11/08/update-gac-ps1.aspx"&gt;HERE&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;You should stop what you are doing and go run that script.&amp;nbsp; If you&amp;#39;ve already done this in the past, it will be harmless but if you haven&amp;#39;t, you&amp;#39;ll be amazed at the improvement in startup times.&amp;nbsp; Please tell all your friends to do this as well.&amp;nbsp;&amp;nbsp; A lot of people don&amp;#39;t know about it and have a bad opinion about PowerShell startup times.&amp;nbsp; After people run it, the typical reaction is, &amp;quot;WOW!&amp;quot;.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;Full Story At Source&lt;/p&gt;</description></item><item><title>Hyper-V PowerShell library - now on Codeplex</title><link>http://hypervoria.com/hyper-v/hyper-v-powershell-library-now-on-codeplex.aspx</link><pubDate>Tue, 15 Jul 2008 17:44:00 GMT</pubDate><guid isPermaLink="false">813e2024-6b0a-4879-b378-ec7112fe0781:12</guid><dc:creator>bink</dc:creator><description>&lt;p&gt;James O&amp;#39;Neill: &lt;/p&gt;
&lt;p&gt;I&amp;#39;ve decided to go ahead and post the PowerShell library I have been working on to &lt;a href="http://www.codeplex.com/PSHyperv"&gt;Codeplex&lt;/a&gt;. I wanted to explain various bits of it here before pulling it all together, but that is taking more time than I wanted. I&amp;#39;ve provided early copies to a few people - John Kelbley&amp;nbsp; used them to good effect at the US tech-ed recently - and I haven&amp;#39;t had too many bug reports so I&amp;#39;ve decided to broaden the audience.&amp;nbsp; &lt;/p&gt;
&lt;p&gt;There&amp;#39;s lot&amp;#39;s of good stuff happening in Hyper-V and scripting right now. &lt;a href="http://blogs.msdn.com/taylorb/archive/2008/06/16/hyper-v-wmi-creating-applying-deleting-virtual-machine-snapshots.aspx" title="Deleting Virtual Machine Snapshots"&gt;Taylor Brown&lt;/a&gt; has a blog with more examples in PowerShell; &lt;a href="http://blogs.msdn.com/virtual_pc_guy/archive/2008/06/11/hyper-v-script-compact-vhd.aspx"&gt;Ben Armstong&lt;/a&gt; has some good stuff too; Ben&amp;#39;s more of a VB guy than a PowerShell one and I&amp;#39;ll probably continue to tease him gently about the fact ... he has a very long script. to compact a VHD. Mine is a 4 line function.&amp;nbsp; Interestingly Taylor&amp;#39;s post contains a &amp;quot;Wait for WMI Job&amp;quot; function and Ben has built in. I might write a similar function and give my functions which return Job IDs a &amp;quot;-WAIT&amp;quot; option in the next major revision. I picked out Taylor and Ben because of their blogs but there have been other people inside Microsoft who have been a great help pulling this together, I wish I&amp;#39;d kept a list of who had pointed me to this or that so I could thank them.&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/p&gt;
&lt;p&gt;The source code is open (as Powershell tends to be) and distributed under the Microsoft public license (MS-PL). &lt;/p&gt;
&lt;p&gt;See also: &lt;a href="http://dungkhoang.spaces.live.com"&gt;http://dungkhoang.spaces.live.com&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description></item><item><title>Hyper-V WMI: Creating/Applying/Deleting Virtual Machine Snapshots </title><link>http://hypervoria.com/hyper-v/hyper-v-wmi-creating-applying-deleting-virtual-machine-snapshots.aspx</link><pubDate>Fri, 11 Jul 2008 19:09:00 GMT</pubDate><guid isPermaLink="false">813e2024-6b0a-4879-b378-ec7112fe0781:13</guid><dc:creator>bink</dc:creator><description>&lt;p&gt;Hyper-V implements a feature known as snapshots, this should not be confused with a SAN snapshot or a VSS snapshot these snapshots are quite different.&amp;nbsp; A Hyper-V snapshot allows you to save off the current state of a virtual machine even while the virtual machine is running or paused.&amp;nbsp; You can then you can revert back to this state at a latter point&amp;hellip;&amp;nbsp; You can create tree&amp;rsquo;s of snapshots (see screen shot), think about application testing when you might need an XP RTM image, XP SP1, XP SP2, XP SP1 that was upgraded to SP2 and then rolled back to SP1 etc&amp;hellip;&amp;nbsp; With a snapshot tree you can create all of these interesting combinations without having to reinstall a physical or virtual machine 20 times&amp;hellip; and when the next service pack comes out you can just apply the interesting base snapshots create a new snapshot and install the service pack &amp;ndash; Major Time Saver!&lt;/p&gt;
&lt;p&gt;The way a snapshot works is that Hyper-V creates a copy of the virtual machine configuration (network connections, disk configuration, cpu count, ram count etc&amp;hellip;) Hyper-V then creates a special diffrencing VHD file known as an AVHD for every virtual hard disk connected to the VM to prevent the current VHD from being changed.&amp;nbsp; If the virtual machine is running a full copy of the guest memory is also saved &amp;ndash; unlike a saved state the virtual machine continues to run while this is occurring.&amp;nbsp; There are a few things that should be noted, since Hyper-V effectively uses a diffrencing VHD to branch the hard disk state VM&amp;rsquo;s that are using passthough disks or cd&amp;rsquo;s can not be snapshoted.&amp;nbsp; Along the same lines just like diffrencing VHD files have a disk read and write performance penalty over a fixed or even dynamically expanding VHD snapshots to incur this cost.&amp;nbsp; Another thing to note is that the AVHD file and saved memory file by default is located in the same location as the virtual machine configuration, this can be changed either by creating the virtual machine in a non-default location or more comely in the Virtual Machine Settings&amp;rsquo;s UI under Management (&lt;em&gt;Snapshot File Location&lt;/em&gt;).&lt;/p&gt;
&lt;p&gt;Snapshot&amp;rsquo;s are excellent for test and development they are a huge time saver.&amp;nbsp; They are also great for staging up a server you get the ability to undo when you accidentally type the wrong machine name or password&amp;hellip; Just remember to merge your snapshots before putting the server into production, to merge a snapshot you just deleted the snapshot tree with the virtual machine off, it will then start a background merge which you can monitor from the Hyper-V management UI.&amp;nbsp; When the merge is completed you will have a flat VHD that you can then put into production with no-performance impact.&amp;nbsp; Now let&amp;rsquo;s see some code!&lt;/p&gt;
&lt;h5&gt;Taking a Snapshot&lt;/h5&gt;
&lt;table bgcolor="#fafafa" cellpadding="0" cellspacing="0"&gt;

&lt;tr&gt;
&lt;td valign="top"&gt;&lt;span style="color:#800080;"&gt;$VMManagementService&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#ff0000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#5f9ea0;"&gt;Get-WmiObject&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#5f9ea0;"&gt;-Namespace&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#0000ff;"&gt;root&lt;/span&gt;&lt;span style="color:#000000;"&gt;\&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;virtualization&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#5f9ea0;"&gt;-Class&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#0000ff;"&gt;Msvm_VirtualSystemManagementService&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;br /&gt;&lt;/span&gt;&lt;span style="color:#800080;"&gt;$SourceVm&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#ff0000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#5f9ea0;"&gt;Get-WmiObject&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#5f9ea0;"&gt;-Namespace&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#0000ff;"&gt;root&lt;/span&gt;&lt;span style="color:#000000;"&gt;\&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;virtualization&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#5f9ea0;"&gt;-Query&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;Select * From Msvm_ComputerSystem Where ElementName=&amp;#39;&lt;span style="color:#800000;"&gt;&lt;strong&gt;VmToSnapshot&lt;/strong&gt;&lt;/span&gt;&amp;#39;&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color:#800080;"&gt;$result&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#ff0000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800080;"&gt;$VMManagementService&lt;/span&gt;&lt;span style="color:#000000;"&gt;.&lt;/span&gt;&lt;span style="color:#8b4513;"&gt;CreateVirtualSystemSnapshot&lt;/span&gt;&lt;span style="color:#000000;"&gt;(&lt;/span&gt;&lt;span style="color:#800080;"&gt;$SourceVm&lt;/span&gt;&lt;span style="color:#000000;"&gt;)&lt;/span&gt; &lt;br /&gt;&lt;span style="color:#008000;"&gt;#ProcessWMIJob($result)&lt;/span&gt; &lt;/td&gt;
&lt;/tr&gt;

&lt;/table&gt;
&lt;h5&gt;Applying a Snapshot&lt;/h5&gt;
&lt;table bgcolor="#fafafa" cellpadding="0" cellspacing="0"&gt;

&lt;tr&gt;
&lt;td valign="top"&gt;&lt;span style="color:#800080;"&gt;$VMManagementService&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#ff0000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#5f9ea0;"&gt;Get-WmiObject&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#5f9ea0;"&gt;-Namespace&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#0000ff;"&gt;root&lt;/span&gt;&lt;span style="color:#000000;"&gt;\&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;virtualization&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#5f9ea0;"&gt;-Class&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#0000ff;"&gt;Msvm_VirtualSystemManagementService&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;br /&gt;&lt;/span&gt;&lt;span style="color:#800080;"&gt;$SourceVm&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#ff0000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#5f9ea0;"&gt;Get-WmiObject&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#5f9ea0;"&gt;-Namespace&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#0000ff;"&gt;root&lt;/span&gt;&lt;span style="color:#000000;"&gt;\&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;virtualization&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#5f9ea0;"&gt;-Query&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;Select * From Msvm_ComputerSystem Where ElementName=&lt;strong&gt;&amp;#39;VmToSnapshot&amp;#39;&lt;/strong&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;br /&gt;&lt;/span&gt;&lt;span style="color:#800080;"&gt;$Snapshot&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#ff0000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#5f9ea0;"&gt;Get-WmiObject&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#5f9ea0;"&gt;-Namespace&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#0000ff;"&gt;root&lt;/span&gt;&lt;span style="color:#000000;"&gt;\&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;virtualization&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#5f9ea0;"&gt;-Query&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;Associators Of {$SourceVm} Where AssocClass=Msvm_ElementSettingData ResultClass=Msvm_VirtualSystemSettingData&amp;quot; &lt;br /&gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color:#800080;"&gt;$result&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#ff0000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800080;"&gt;$VMManagementService&lt;/span&gt;&lt;span style="color:#000000;"&gt;.&lt;/span&gt;&lt;span style="color:#8b4513;"&gt;ApplyVirtualSystemSnapshot&lt;/span&gt;&lt;span style="color:#000000;"&gt;(&lt;/span&gt;&lt;span style="color:#800080;"&gt;$SourceVm&lt;/span&gt;&lt;span style="color:#000000;"&gt;,&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800080;"&gt;$Snapshot&lt;/span&gt;&lt;span style="color:#000000;"&gt;)&lt;/span&gt; &lt;br /&gt;&lt;span style="color:#008000;"&gt;#ProcessWMIJob($result)&lt;/span&gt; &lt;/td&gt;
&lt;/tr&gt;

&lt;/table&gt;
&lt;h5&gt;Deleting a Snapshot&lt;/h5&gt;
&lt;table bgcolor="#fafafa" cellpadding="0" cellspacing="0"&gt;

&lt;tr&gt;
&lt;td valign="top"&gt;&lt;span style="color:#800080;"&gt;$VMManagementService&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#ff0000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#5f9ea0;"&gt;Get-WmiObject&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#5f9ea0;"&gt;-Namespace&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#0000ff;"&gt;root&lt;/span&gt;&lt;span style="color:#000000;"&gt;\&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;virtualization&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#5f9ea0;"&gt;-Class&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#0000ff;"&gt;Msvm_VirtualSystemManagementService &lt;br /&gt;&lt;/span&gt;&lt;span style="color:#800080;"&gt;$SourceVm&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#ff0000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#5f9ea0;"&gt;Get-WmiObject&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#5f9ea0;"&gt;-Namespace&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#0000ff;"&gt;root&lt;/span&gt;&lt;span style="color:#000000;"&gt;\&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;virtualization&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#5f9ea0;"&gt;-Query&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;Select * From Msvm_ComputerSystem Where ElementName=&amp;#39;&lt;strong&gt;VmToSnapshot&lt;/strong&gt;&amp;#39;&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;br /&gt;&lt;/span&gt;&lt;span style="color:#800080;"&gt;$Snapshot&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#ff0000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#5f9ea0;"&gt;Get-WmiObject&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#5f9ea0;"&gt;-Namespace&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#0000ff;"&gt;root&lt;/span&gt;&lt;span style="color:#000000;"&gt;\&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;virtualization&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#5f9ea0;"&gt;-Query&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;Associators Of {$SourceVm} Where AssocClass=Msvm_ElementSettingData ResultClass=Msvm_VirtualSystemSettingData&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;br /&gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color:#800080;"&gt;$result&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#ff0000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800080;"&gt;$VMManagementService&lt;/span&gt;&lt;span style="color:#000000;"&gt;.&lt;/span&gt;&lt;span style="color:#8b4513;"&gt;RemoveVirtualSystemSnapshot&lt;/span&gt;&lt;span style="color:#000000;"&gt;(&lt;/span&gt;&lt;span style="color:#800080;"&gt;$Snapshot&lt;/span&gt;&lt;span style="color:#000000;"&gt;)&lt;/span&gt; &lt;br /&gt;&lt;span style="color:#008000;"&gt;#ProcessWMIJob($result)&lt;/span&gt; &lt;/td&gt;
&lt;/tr&gt;

&lt;/table&gt;
&lt;p&gt;Continue for more at source!&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description></item></channel></rss>