{"id":138,"date":"2010-04-19T21:25:17","date_gmt":"2010-04-19T20:25:17","guid":{"rendered":"http:\/\/read.virtualizeplanet.com\/?p=138"},"modified":"2010-05-09T22:48:11","modified_gmt":"2010-05-09T21:48:11","slug":"powercli-lesson-1","status":"publish","type":"post","link":"https:\/\/read.virtualizeplanet.com\/?p=138","title":{"rendered":"PowerCLI: Lesson #1"},"content":{"rendered":"<p>Ok before we begin I have to pay homage to where I\u2019m getting my learning material from.<\/p>\n<p>1. To learn PowerShell I\u2019m using the Microsoft \u201cWindows PowerShell step-by-step\u201d book.<\/p>\n<p><a href=\"http:\/\/virtualizeplanet.com\/wordpress\/wp-content\/uploads\/2010\/04\/PS-step-by-step.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-147\" title=\"PS-step-by-step\" src=\"http:\/\/virtualizeplanet.com\/wordpress\/wp-content\/uploads\/2010\/04\/PS-step-by-step.jpg\" alt=\"\" width=\"110\" height=\"110\" srcset=\"https:\/\/read.virtualizeplanet.com\/wp-content\/uploads\/2010\/04\/PS-step-by-step.jpg 110w, https:\/\/read.virtualizeplanet.com\/wp-content\/uploads\/2010\/04\/PS-step-by-step-50x50.jpg 50w\" sizes=\"auto, (max-width: 110px) 100vw, 110px\" \/><\/a><\/p>\n<p><a href=\"http:\/\/i13.tinypic.com\/66ufiiw.jpg\"><\/a><\/p>\n<p>2. To Learn PowerCLI initially I\u2019ll be referring to Hal Rottenberg\u2019s Book \u201cManaging VMware Infrastructure with Windows PowerShell \u201c \u00a0and Trainsignal Pro Series Vol1 CBT (Hal Rottenberg)<\/p>\n<p>\u00a0<a href=\"http:\/\/virtualizeplanet.com\/wordpress\/wp-content\/uploads\/2010\/04\/hal.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-144\" title=\"hal rottenberg\" src=\"http:\/\/virtualizeplanet.com\/wordpress\/wp-content\/uploads\/2010\/04\/hal.jpg\" alt=\"\" width=\"91\" height=\"130\" \/><\/a>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<a href=\"http:\/\/virtualizeplanet.com\/wordpress\/wp-content\/uploads\/2010\/04\/TS.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-148\" title=\"TrainSignal\" src=\"http:\/\/virtualizeplanet.com\/wordpress\/wp-content\/uploads\/2010\/04\/TS.jpg\" alt=\"\" width=\"126\" height=\"128\" srcset=\"https:\/\/read.virtualizeplanet.com\/wp-content\/uploads\/2010\/04\/TS.jpg 126w, https:\/\/read.virtualizeplanet.com\/wp-content\/uploads\/2010\/04\/TS-50x50.jpg 50w\" sizes=\"auto, (max-width: 126px) 100vw, 126px\" \/><\/a>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<a href=\"http:\/\/images.google.co.uk\/imgres?imgurl=http:\/\/blogs.virtualizationadmin.com\/davis\/wp-content\/blogs\/59\/files\/2009\/05\/Managing%2520VMWare%2520Infrastructure%2520with%2520Windows%2520PowerShell.jpg&amp;imgrefurl=http:\/\/blogs.virtualizationadmin.com\/davis\/2009\/05\/&amp;usg=__IUvfN2L9rcXbYx_GmBtOLv8L5bs=&amp;h=500&amp;w=500&amp;sz=39&amp;hl=en&amp;start=1&amp;um=1&amp;itbs=1&amp;tbnid=rCSV0qfHl9oI6M:&amp;tbnh=130&amp;tbnw=130&amp;prev=\/images%3Fq%3DHal%2BRottenberg%26um%3D1%26hl%3Den%26safe%3Doff%26sa%3DX%26tbs%3Disch:1\">\u00a0<\/a>\u00a0<a href=\"http:\/\/images.google.co.uk\/imgres?imgurl=http:\/\/imgarchive.info\/201002\/307225.jpg&amp;imgrefurl=http:\/\/mrkiemcun.softarchive.net\/trainsignal_vmware_vsphere_pro_series_training_vol_additional_content_dvd.203404.html&amp;usg=__FlH33_C7eg1wYbZxX-P1uM4GewY=&amp;h=457&amp;w=450&amp;sz=48&amp;hl=en&amp;start=7&amp;um=1&amp;itbs=1&amp;tbnid=wQf1uO7PVhKNYM:&amp;tbnh=128&amp;tbnw=126&amp;prev=\/images%3Fq%3DHal%2BRottenberg%26um%3D1%26hl%3Den%26safe%3Doff%26sa%3DX%26tbs%3Disch:1\"> <\/a><\/p>\n<p>3. I\u2019m sure some were down the line I\u2019ll be referring to the UK guru for PowerCLI Alan Renouf, <a href=\"http:\/\/www.virtu-al.net\/\">http:\/\/www.virtu-al.net\/<\/a><\/p>\n<p>4. And if I really have to RTFM then its opening up the Admin guide found : <a href=\"http:\/\/www.vmware.com\/support\/developer\/windowstoolkit\/wintk40u1\/doc\/viwin_admg.pdf\">http:\/\/www.vmware.com\/support\/developer\/windowstoolkit\/wintk40u1\/doc\/viwin_admg.pdf<\/a><\/p>\n<p>\u00a0The first steps should be to install:<\/p>\n<p>Step1 Download and install PowerShell from Microsoft if your Operating system doesn\u2019t already have it installed.<\/p>\n<p>Step2 Download and install PowerCLI from VMware<\/p>\n<p>You should then see an icon on your desktop like this:<\/p>\n<p>\u00a0<a href=\"http:\/\/virtualizeplanet.com\/wordpress\/wp-content\/uploads\/2010\/04\/PowerCLI.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-146\" title=\"PowerCLI\" src=\"http:\/\/virtualizeplanet.com\/wordpress\/wp-content\/uploads\/2010\/04\/PowerCLI.jpg\" alt=\"\" width=\"96\" height=\"96\" srcset=\"https:\/\/read.virtualizeplanet.com\/wp-content\/uploads\/2010\/04\/PowerCLI.jpg 96w, https:\/\/read.virtualizeplanet.com\/wp-content\/uploads\/2010\/04\/PowerCLI-50x50.jpg 50w\" sizes=\"auto, (max-width: 96px) 100vw, 96px\" \/><\/a><\/p>\n<p>This is PowerCLI console. It\u2019s actually a PowerShell script that prepares a PowerShell console with the VMware snap-in and some initial useful information like popular PowerCLI commands.<\/p>\n<p>Alternatively you can open up a standard PowerShell console and use the following command-let to manually add in the VMware snap-in:<\/p>\n<p>\u00a0<a href=\"http:\/\/virtualizeplanet.com\/wordpress\/wp-content\/uploads\/2010\/04\/Addsnap.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-139\" title=\"Addsnap\" src=\"http:\/\/virtualizeplanet.com\/wordpress\/wp-content\/uploads\/2010\/04\/Addsnap.jpg\" alt=\"\" width=\"522\" height=\"14\" srcset=\"https:\/\/read.virtualizeplanet.com\/wp-content\/uploads\/2010\/04\/Addsnap.jpg 522w, https:\/\/read.virtualizeplanet.com\/wp-content\/uploads\/2010\/04\/Addsnap-300x8.jpg 300w\" sizes=\"auto, (max-width: 522px) 100vw, 522px\" \/><\/a><\/p>\n<p>Step 3.<\/p>\n<p>Now you are ready to go and connect to your vCenter or ESX server using the following command:<\/p>\n<p>\u00a0<a href=\"http:\/\/virtualizeplanet.com\/wordpress\/wp-content\/uploads\/2010\/04\/connect-vc.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-142\" title=\"connect-vc\" src=\"http:\/\/virtualizeplanet.com\/wordpress\/wp-content\/uploads\/2010\/04\/connect-vc.jpg\" alt=\"\" width=\"243\" height=\"14\" \/><\/a><\/p>\n<p>You will be prompted with a certificate error which is normal unless you decided to use a trusted root certificate\/authority with your vSphere deployment:<\/p>\n<p>\u00a0<a href=\"http:\/\/virtualizeplanet.com\/wordpress\/wp-content\/uploads\/2010\/04\/cert-error.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-141\" title=\"cert-error\" src=\"http:\/\/virtualizeplanet.com\/wordpress\/wp-content\/uploads\/2010\/04\/cert-error.jpg\" alt=\"\" width=\"557\" height=\"68\" srcset=\"https:\/\/read.virtualizeplanet.com\/wp-content\/uploads\/2010\/04\/cert-error.jpg 557w, https:\/\/read.virtualizeplanet.com\/wp-content\/uploads\/2010\/04\/cert-error-300x36.jpg 300w\" sizes=\"auto, (max-width: 557px) 100vw, 557px\" \/><\/a><\/p>\n<p>You will then be promoted to provide your vSphere credentials, so enter you username and password:<\/p>\n<p>\u00a0<a href=\"http:\/\/virtualizeplanet.com\/wordpress\/wp-content\/uploads\/2010\/04\/Authenticate.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-140\" title=\"Authenticate\" src=\"http:\/\/virtualizeplanet.com\/wordpress\/wp-content\/uploads\/2010\/04\/Authenticate.jpg\" alt=\"\" width=\"325\" height=\"254\" srcset=\"https:\/\/read.virtualizeplanet.com\/wp-content\/uploads\/2010\/04\/Authenticate.jpg 325w, https:\/\/read.virtualizeplanet.com\/wp-content\/uploads\/2010\/04\/Authenticate-300x234.jpg 300w\" sizes=\"auto, (max-width: 325px) 100vw, 325px\" \/><\/a><\/p>\n<p>You can enter these parameters at the command-line too but we\u2019ll see that in a later lesson.<\/p>\n<p>Step 4<\/p>\n<p>Now we are connected to our VMware environment let\u2019s do something useful.\u00a0 Let\u2019s run a popular PowerCLI command-let, Get-VM which lists all the VMs from the root level of your inventory and provide some rudimentary information like how many CPUs and how much memory each VM has:<\/p>\n<p><a href=\"http:\/\/virtualizeplanet.com\/wordpress\/wp-content\/uploads\/2010\/04\/GEt-VM.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-143\" title=\"GEt-VM\" src=\"http:\/\/virtualizeplanet.com\/wordpress\/wp-content\/uploads\/2010\/04\/GEt-VM.jpg\" alt=\"\" width=\"421\" height=\"182\" srcset=\"https:\/\/read.virtualizeplanet.com\/wp-content\/uploads\/2010\/04\/GEt-VM.jpg 421w, https:\/\/read.virtualizeplanet.com\/wp-content\/uploads\/2010\/04\/GEt-VM-300x129.jpg 300w\" sizes=\"auto, (max-width: 421px) 100vw, 421px\" \/><\/a><\/p>\n<p>So in layman\u2019s terms I\u2019m going to try to explain what\u2019s going on.\u00a0 PowerCLI command-lets \u00a0are based on .Net libraries used to interface with VMware\u2019s vSphere SDK (API) . VMware has developed a mature, feature rich, extensive and powerful API for its ESX\/vCenter platforms. This API is interfaced using web services which allows anyone to develop VMware\u00a0applications using just about any language including me (see my downloads section).<\/p>\n<p>When connected to the API it offers up the Virtual Infrastructure in the form of a hierarchical inventory or tree of objects:<\/p>\n<p>\u00a0<a href=\"http:\/\/virtualizeplanet.com\/wordpress\/wp-content\/uploads\/2010\/04\/MOB.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-145\" title=\"MOB\" src=\"http:\/\/virtualizeplanet.com\/wordpress\/wp-content\/uploads\/2010\/04\/MOB.jpg\" alt=\"\" width=\"734\" height=\"279\" \/><\/a><\/p>\n<p>These objects\u00a0include ESX servers, VMs , DataCenters and so on. These objects have properties and actions (methods) that can be performed on them. For example a VM could have a properties which holds a value that shows how many CPUs are configured on this VM or a method which when manipulated can change the power state of a VM to off or on.<\/p>\n<p>This SDK exists both on ESX and vCenter and is all most exactly the same on both platforms expect the vCenter version has a few more objects to manage the feature you wouldn\u2019t normally see on a standalone ESX server like DRS for example:<\/p>\n<p>\u00a0<a href=\"http:\/\/virtualizeplanet.com\/wordpress\/wp-content\/uploads\/2010\/04\/sdk.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-149\" title=\"sdk\" src=\"http:\/\/virtualizeplanet.com\/wordpress\/wp-content\/uploads\/2010\/04\/sdk.jpg\" alt=\"\" width=\"447\" height=\"429\" srcset=\"https:\/\/read.virtualizeplanet.com\/wp-content\/uploads\/2010\/04\/sdk.jpg 447w, https:\/\/read.virtualizeplanet.com\/wp-content\/uploads\/2010\/04\/sdk-300x287.jpg 300w\" sizes=\"auto, (max-width: 447px) 100vw, 447px\" \/><\/a><\/p>\n<p>You\u2019ll often hear the term Managed Object Reference. The way I perceive this term is that when you are manipulating an object like a VM what\u2019s actually happening is you are presented with a\u00a0 reference to the object which you can work with locally and changes are sent down the line for the SDK to action within vSphere. This allows you to work with a great number of objects locally without the overhead of constantly to refreshing the inventory.<\/p>\n<p>I know this is a lot to take in but it\u2019s the only way I can think of explaining it so non-developers would understand it.<\/p>\n<p>The beauty of PowerCLI is you don\u2019t have to be a developer and the\u00a0pain-points of developing the SDK to perform the tasks you would like to see are transparent and masked away (simplified) so you don\u2019t have to worry about them.<\/p>\n<p>We have looked at 2 lines of code which first helped us connect to vSphere and secondly list out all the VMs. Now if I had to do that let\u2019s say in C# languages with the SDK it would take 40 to 50 lines of code.<\/p>\n<p>\u00a0We&#8217;ll leave it there for lesson#1\u00a0and look out for lesson#2 shortly.<\/p>\n<p><a title=\"PowerCLI Newbie\" href=\"http:\/\/read.virtualizeplanet.com\/?p=136\">Previous<\/a> &#8211; <a title=\"PowerCLI: Lesson #2\" href=\"http:\/\/read.virtualizeplanet.com\/?p=157\">Next<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Ok before we begin I have to pay homage to where I\u2019m getting my learning material from. 1. To learn PowerShell I\u2019m using the Microsoft \u201cWindows PowerShell step-by-step\u201d book. 2. To Learn PowerCLI initially I\u2019ll be referring to Hal Rottenberg\u2019s Book \u201cManaging VMware Infrastructure with Windows PowerShell \u201c \u00a0and Trainsignal Pro Series Vol1 CBT (Hal [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,4],"tags":[],"class_list":["post-138","post","type-post","status-publish","format-standard","hentry","category-powersehll","category-vmware"],"aioseo_notices":[],"views":27047,"_links":{"self":[{"href":"https:\/\/read.virtualizeplanet.com\/index.php?rest_route=\/wp\/v2\/posts\/138","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/read.virtualizeplanet.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/read.virtualizeplanet.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/read.virtualizeplanet.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/read.virtualizeplanet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=138"}],"version-history":[{"count":5,"href":"https:\/\/read.virtualizeplanet.com\/index.php?rest_route=\/wp\/v2\/posts\/138\/revisions"}],"predecessor-version":[{"id":152,"href":"https:\/\/read.virtualizeplanet.com\/index.php?rest_route=\/wp\/v2\/posts\/138\/revisions\/152"}],"wp:attachment":[{"href":"https:\/\/read.virtualizeplanet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=138"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/read.virtualizeplanet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=138"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/read.virtualizeplanet.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=138"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}