TechProsaic
(powershell & other stuff)
« You Want Free Stuff? I Want More Entries!
I Found a Vista Killer Feature: Sideshow »
2008-8
17

VMware PowerShell Toolkit Tip: Moving Templates

In:Powershell, VMware by halr9000
Tags: Performance,Powershell,Scripting,VMware
spacer

I was surprised this morning to find that you can’t directly move templates using the existing cmdlets.  Looks like you can either a) change template to a VM using set-template or b) use Get-View on a Folder object and then call its MoveIntoFolder_Task method.

Method A – there and back again

   1: $vm = Get-Template wind* | Set-Template -ToVM |
   2:     Move-VM -Destination (Get-Folder templates)
   3: $vmView = $vm | Get-View
   4: $vmView.MarkAsTemplate()

TotalSeconds      : 8.9222029

Method B – do it folder style

This one should be much faster…let’s see:

   1: $TmplView = Get-Template wind* | Get-View
   2: $FolderView = Get-Folder Templates | Get-View
   3: $FolderView.MoveIntoFolder( $TmplView.MoRef )

TotalSeconds      : 2.0466224

We have a winner spacer

Note that I didn’t actually use MoveIntoFolder_Task(), I used just MoveIntoFolder().  The former will create a task and queue the operation, returning control to your script immediately. That’s good for some things but not for the purposes of measuring the timing.  spacer

Also note that the timing was performed on my home lab.  I imagine on nice hardware method B would take less than a second.

Permalink to : halr9000.com/article/591

3 Comments
RSS for this comments | Trackback URI
( Show All | Hide All ) Post a comment now »
get-admin :: Provisioning server for VM’s
2008-08-27 13:08:01

[...] templates.  Anyways they where everywhere, and I was not looking forward to this.  Then I read this post From Hal’s blog, and quickly realized that with was something worth scripting.  The version I used at work looked [...]

Reply to this comment
glnsize
2008-08-27 13:14:52

Thank’s for the head start, my problem was that I needed to physically move my templates to a specific host. Your post got me 99% there!

~Glenn

Reply to this comment
halr9000
2008-08-27 13:39:58

Glad I could help spacer

Reply to this comment

« You Want Free Stuff? I Want More Entries!
I Found a Vista Killer Feature: Sideshow »
  • Microblog

  • Recent Posts

  • Recent Comments

  • meta

  • PowerShell Blogroll

  • Powered by WordPress 3.0 - The Enhancing Spring (TES) by aw - 0.94 seconds
    gipoco.com is neither affiliated with the authors of this page nor responsible for its contents. This is a safe-cache copy of the original web site.