<?xml version="1.0" encoding="utf-8"?><?xml-stylesheet type='text/xsl' href='http://dverweij.spaces.live.com/mmm2008-07-24_12.50/rsspretty.aspx?rssquery=en-US;http%3a%2f%2fdverweij.spaces.live.com%2fcategory%2fVMware%2ffeed.rss' version='1.0'?><rss version="2.0" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:msn="http://schemas.microsoft.com/msn/spaces/2005/rss" xmlns:live="http://schemas.microsoft.com/live/spaces/2006/rss" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:cf="http://www.microsoft.com/schemas/rss/core/2005" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Just Powershell it: VMware</title><description /><link>http://dverweij.spaces.live.com/?_c11_BlogPart_BlogPart=blogview&amp;_c=BlogPart&amp;partqs=catVMware</link><language>en-US</language><pubDate>Sat, 12 Jul 2008 01:36:10 GMT</pubDate><lastBuildDate>Sat, 12 Jul 2008 01:36:10 GMT</lastBuildDate><generator>Microsoft Spaces v1.1</generator><docs>http://www.rssboard.org/rss-specification</docs><ttl>60</ttl><cf:parentRSS>http://dverweij.spaces.live.com/blog/feed.rss</cf:parentRSS><live:type>blogcategory</live:type><live:identity><live:id>-6645245869990399496</live:id><live:alias>dverweij</live:alias></live:identity><cf:listinfo><cf:group ns="http://schemas.microsoft.com/live/spaces/2006/rss" element="typelabel" label="Type" /><cf:group ns="http://schemas.microsoft.com/live/spaces/2006/rss" element="tag" label="Tag" /><cf:group element="category" label="Category" /><cf:sort element="pubDate" label="Date" data-type="date" default="true" /><cf:sort element="title" label="Title" data-type="string" /><cf:sort ns="http://purl.org/rss/1.0/modules/slash/" element="comments" label="Comments" data-type="number" /></cf:listinfo><item><title>VMware COM API</title><link>http://dverweij.spaces.live.com/Blog/cns!A3C75816DA1731F8!155.entry</link><description>&lt;div&gt;It has been a while since I last posted a new entry, but time has yet again not been my best friend.&lt;/div&gt;
&lt;div&gt;The last months I've been busy with virtualizations and VMware VI3 in particulair. I wouldn't be me if I wouldn't try leveraging the power of Powershell with VMware. I'm still working on ways to use the VMware SDK with powershell and that means a whole challenge of  really understanding C# and the VMware SDK to write cmdlets. Still nothing to post on this, but there are ways to use powershell to manage VMware infrastructures. This is done throught the VMware COM API. &lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;As shown with earlier postings about Citrix it is easy to use COM objects in Powershell. This is the same for VMware.&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;I will not post an indepth description of how to do all the possible tasks, but it should be enough to get you going. The VMware scripting API is less powerfull than the SDK. Tasks like for instance migrating a VM or creating a VM are not possible through the SDK, but tasks like power operations, taking snapshot, deleting snapshots and so on &lt;u&gt;are&lt;/u&gt; possible and that makes it exciting!&lt;/div&gt;
&lt;div&gt;Before starting working with the API, first download and install the API at: &lt;a href="http://www.vmware.com/download/sdk/api.html"&gt;http://www.vmware.com/download/sdk/api.html&lt;/a&gt;&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;For detailed information about the API download the manual from VMware at: &lt;font face=Arial size=2&gt; &lt;/font&gt;&lt;a href="http://www.vmware.com/pdf/Scripting_API_23.pdf"&gt;&lt;font face=Arial color=blue size=2&gt;&lt;u&gt;http://www.vmware.com/pdf/Scripting_API_23.pdf&lt;/u&gt;&lt;/font&gt;&lt;/a&gt; &lt;/div&gt;
&lt;div&gt;There are some perl and vbscript samples in the document and this can easily be translated in powershell.&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;Oke, now let's just connect to a VI3 host. Just type the following in the commandline.&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;ps/&amp;gt; $cp=new-object -com vmcom.vmconnectparams&lt;/div&gt;
&lt;div&gt;ps/&amp;gt; $cp.hostname= &amp;quot;ESXhostname&amp;quot;&lt;/div&gt;
&lt;div&gt;ps/&amp;gt; $cp.username= &amp;quot;root&amp;quot;  #use a username with enough permissions on the ESX host.&lt;/div&gt;
&lt;div&gt;ps/&amp;gt; $cp.password= &amp;quot;password&amp;quot;&lt;/div&gt;
&lt;div&gt;ps/&amp;gt; $srv=new-object -com vmcom.vmserverctl&lt;/div&gt;
&lt;div&gt;ps/&amp;gt; $srv.connect($cp)&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;now you are connected to the host. If you type $srv you'll get the vm's registered on the host. A better readable list is created by using:&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;ps/&amp;gt; $srv.RegisteredVmNames&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;You'll see that the listing actually shows the .vmx files on the host.&lt;/div&gt;
&lt;div&gt;Of cource you can get the members of the object by using get-member&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;ps/&amp;gt; $srv|gm&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;To connect to a particulair VM do the following&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;option 1:&lt;/div&gt;
&lt;div&gt;copy the complete name of a vmx file path from the previous listing and put it in a variable, lets say $vmname&lt;/div&gt;
&lt;div&gt;Now type the following:&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;ps/&amp;gt; $vm=new-object -com vmcom.vmctl &lt;/div&gt;
&lt;div&gt;ps/&amp;gt; $vm.connect($cp,$vmname)&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;If we than look at the members by using get-member we see what we can do with it.&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;Let say we want to see if the virtual machine has snapshots. You do the following:&lt;/div&gt;
&lt;div&gt;ps/&amp;gt; $vm.HasSnapshot&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;If there is a snapshot, 1 is returned. Otherwise 0 is returned.&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;Option 2:&lt;/div&gt;
&lt;div&gt;If you know the servername of the virtual machine (say server15) and you want to query it directly you can do the following:&lt;/div&gt;
&lt;div&gt;ps/&amp;gt; $srv.RegisteredVmNames|where {$_ -like &amp;quot;*server15*&amp;quot;}|$vm.connect($cp,$_)&lt;/div&gt;
&lt;div&gt;ps/&amp;gt; $vm.HasSnapshot&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;Of cource you must allready have created the $vm object as shown above. Same is for the example below.&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;Option 3:&lt;/div&gt;
&lt;div&gt;If we want to know which VM's have snapshots we can do the following:&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;ps/&amp;gt; $srv.RegisteredVmNames| foreach {&lt;/div&gt;
&lt;div&gt;&amp;gt;&amp;gt; $vm.connect($cp,$_)&lt;/div&gt;
&lt;div&gt;&amp;gt;&amp;gt; if ($vm.HasSnapshot -gt 0)&lt;/div&gt;
&lt;div&gt;&amp;gt;&amp;gt; {&lt;/div&gt;
&lt;div&gt;&amp;gt;&amp;gt; $_&lt;/div&gt;
&lt;div&gt;&amp;gt;&amp;gt; }&lt;/div&gt;
&lt;div&gt;&amp;gt;&amp;gt; }&lt;/div&gt;
&lt;div&gt;ps/&amp;gt; &lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;As said before, this is not a complete description of the VMware API, but just a brief introduction. This should get you on the go and create some nice scripts to make you're life at least a little easier. &lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;Oke, this is it for now, but I promise updates will follow soon.&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;Greetings&lt;/div&gt;
&lt;div&gt;Dennis Verweij&lt;/div&gt;
&lt;div&gt;&lt;a href="http://dverweij.spaces.live.com/"&gt;http://dverweij.spaces.live.com&lt;/a&gt;&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt; &lt;/div&gt;&lt;img src="http://c.services.spaces.live.com/CollectionWebService/c.gif?cid=-6645245869990399496&amp;page=RSS%3a+VMware+COM+API&amp;referrer=" width="1px" height="1px" border="0" alt=""&gt;&lt;img style="position:absolute" alt="" width="0px" height="0px" src="http://c.live.com/c.gif?NC=31263&amp;amp;NA=1149&amp;amp;PI=73329&amp;amp;RF=&amp;amp;DI=3919&amp;amp;PS=85545&amp;amp;TP=dverweij.spaces.live.com&amp;amp;GT1=dverweij"&gt;</description><comments>http://dverweij.spaces.live.com/Blog/cns!A3C75816DA1731F8!155.entry#comment</comments><guid isPermaLink="true">http://dverweij.spaces.live.com/Blog/cns!A3C75816DA1731F8!155.entry</guid><pubDate>Thu, 16 Aug 2007 13:01:00 GMT</pubDate><slash:comments>3</slash:comments><msn:type>blogentry</msn:type><live:type>blogentry</live:type><live:typelabel>Blog entry</live:typelabel><wfw:commentRss>http://dverweij.spaces.live.com/blog/cns!A3C75816DA1731F8!155/comments/feed.rss</wfw:commentRss><wfw:comment>http://dverweij.spaces.live.com/Blog/cns!A3C75816DA1731F8!155.entry#comment</wfw:comment><dcterms:modified>2007-08-16T13:01:57Z</dcterms:modified></item></channel></rss>