Powershell

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 :)

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.  :)

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

: http://halr9000.com/article/591

( Show All | Hide All ) Post a comment now » Sorry, the comments are closed.
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 [...]

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

2008-08-27 13:39:58

Glad I could help :)

Sorry, the comment form is closed at this time.

  • Microblog

  • Recent Posts

  • Recent Comments

  • meta