Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Learning PowerCLI for VMware VSphere
Learning PowerCLI for VMware VSphere

Learning PowerCLI for VMware VSphere: Automate your Vmware vSphere environment by learning how to install and use PowerCLI. This book takes a practical tutorial approach that will have you automating your daily routine tasks in no time.

Arrow left icon
Profile Icon Robert van den Nieuwendijk
Arrow right icon
£19.99 £28.99
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.9 (15 Ratings)
eBook Feb 2014 374 pages Edition
eBook
£19.99 £28.99
Paperback
£37.99
Subscription
Free Trial
Renews at £16.99p/m
Arrow left icon
Profile Icon Robert van den Nieuwendijk
Arrow right icon
£19.99 £28.99
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.9 (15 Ratings)
eBook Feb 2014 374 pages Edition
eBook
£19.99 £28.99
Paperback
£37.99
Subscription
Free Trial
Renews at £16.99p/m
eBook
£19.99 £28.99
Paperback
£37.99
Subscription
Free Trial
Renews at £16.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Learning PowerCLI for VMware VSphere

Chapter 2. Learning Basic PowerCLI Concepts

While learning something new, you always have to learn the basics first. In this chapter, you will learn some basic PowerShell and PowerCLI concepts. Knowing these concepts will make it easier for you to learn the advanced topics. We will cover the following topics in this chapter:

  • Using the Get-Command, Get-Help, and Get-Member cmdlets

  • Using providers and PSDrives

  • Using arrays and hash tables

  • Creating calculated properties

  • Using raw API objects with ExtensionData or Get-View

  • Extending PowerCLI objects with the New-VIProperty cmdlet

  • Working with vSphere folders

Using the Get-Command, Get-Help, and Get-Member cmdlets


There are some PowerShell cmdlets that everyone should know. Knowing these cmdlets will help you to discover other cmdlets, their functions, parameters, and returned objects.

Using Get-Command

The first cmdlet that you should know is Get-Command. This cmdlet returns all of the commands that are installed on your computer. The Get-Command cmdlet has the following syntax:

Get-Command [[-ArgumentList] <Object[]>] [-All] [-ListImported] [-Module <String[]>] [-Noun <String[]>] [-ParameterName <String[]>] [-ParameterType <PSTypeName[]>] [-Syntax] [-TotalCount <Int32>] [-Verb <String[]>] [<CommonParameters>]
Get-Command [[-Name] <String[]>] [[-ArgumentList] <Object[]>] [-All] [-CommandType <CommandTypes>] [-ListImported] [-Module <String[]>] [-ParameterName <String[]>] [-ParameterType <PSTypeName[]>] [-Syntax] [-TotalCount <Int32>] [<CommonParameters...

Using providers and PSDrives


Until now, you have only seen cmdlets. Cmdlets are PowerShell commands. However, PowerShell has another import concept named providers. Providers are accessed through named drives or PSDrives. In the following sections, providers and PSDrives will be explained.

Using providers

A PowerShell provider is a piece of software that makes data stores look like filesystems. PowerShell providers are usually part of a snap-in or a module-like PowerCLI. The advantage of providers is that you can use the same cmdlets for all of the providers. These cmdlets have the following nouns: Item, ChildItem, Content, and ItemProperty. You can use the Get-Command cmdlet to get a list of all of the cmdlets with these nouns:

PowerCLI C:> Get-Command -Noun Item,ChildItem,Content,ItemProperty

CommandType Name                ModuleName
----------- ----                ----------
Cmdlet      Add-Content         Microsoft.PowerShell.Management
Cmdlet      Clear-Content       Microsoft...

Using arrays and hash tables


In PowerCLI, you can create a list of objects. For example, "red","white","blue" is a list of strings. In PowerShell, a list of terms is called an array. An array can have zero or more objects. You can create an empty array and assign it to a variable:

PowerCLI C:\> $Array = @()

You can fill the array during creation using the following command line:

PowerCLI C:\> $Array = @("red","white")

You can use the += operator to add an element to an array:

PowerCLI C:\> $Array += "blue"
PowerCLI C:\> $Array
red
white
blue

If you want to retrieve a specific element of an array, you can use an index starting with 0 for the first element, 1 for the second element, and so on. If you want to retrieve an element from the tail of the array, you have to use -1 for the last element, -2 for the second to last, and so on. You have to use square brackets around the index number. In the next example, the first element of the array is retrieved using the following command...

Creating calculated properties


You can use the Select-Object cmdlet to select certain properties of the objects that you want to return. For example, you can use the following code to return the name and the used space, in GB, of your virtual machines:

PowerCLI C:\> Get-VM | Select-Object -Property Name,UsedSpaceGB

But what if you want to return the used space in MB? The PowerCLI VirtualMachineImpl object has no UsedSpaceMB property. This is where you can use a calculated property. A calculated property is a PowerShell hash table with two elements: Name and Expression. The Name element contains the name that you want to give the calculated property. The Expression element contains a scriptblock with PowerCLI code to calculate the value of the property. To return the name and the used space in MB for all of your virtual machines, run the following command:

PowerCLI C:\> Get-VM |
>> Select-Object -Property Name,
>> @{Name="UsedSpaceMB";Expression={1KB*$_.UsedSpaceGB}}
&gt...

Using raw API objects with ExtensionData or Get-View


PowerCLI makes it easy to use the VMware vSphere application programming interface (API). There are two ways to do this. The first one is by using the ExtensionData property that most of the PowerCLI objects have. The Extensiondata property is a direct link to the vSphere API object related to the PowerCLI object. The second way is by using the Get-View cmdlet to retrieve the vSphere API object related to a PowerCLI object. Both these ways will be discussed in the following sections.

Using the ExtensionData property

Most PowerCLI objects, such as VirtualMachineImpl and VMHostImpl, have a property called ExtensionData. This property is a reference to a view of a VMware vSphere object as described in the "VMware vSphere API Reference Documentation". For example, the ExtensionData property of the PowerCLI's VirtualMachineImpl object links to a vSphere VirtualMachine object view. ExtensionData is a very powerful property because it allows you...

Extending PowerCLI objects with the New-VIProperty cmdlet


Sometimes you can have the feeling that a PowerCLI object is missing a property. Although the VMware PowerCLI team tried to include the most useful properties in the objects, you can have the need for an extra property. Luckily, PowerCLI has a way to extend a PowerCLI object using the New-VIProperty cmdlet. This cmdlet has the following syntax:

New-VIProperty [-Name] <String> [-ObjectType] <String[]> [-Value] <ScriptBlock> [-Force] [-BasedOnExtensionProperty <String[]>] [-WhatIf] [-Confirm][<CommonParameters>]
New-VIProperty [-Name] <String> [-ObjectType] <String[]> [-Force] [-ValueFromExtensionProperty] <String> [-WhatIf] [-Confirm] [<CommonParameters>]

Let's start with an example. You will add the VMware Tools' running statuses used in a previous example to the VirtualMachineImpl object using the New-VIProperty cmdlet:

PowerCLI C:\> New-VIProperty -ObjectType VirtualMachine...

Working with vSphere folders


In a VMware vSphere environment, you can use folders to organize your infrastructure. In the vSphere web client, you can create folders in the Hosts and Clusters, VMs and Templates, Storage, and Networking inventories. The following screenshot shows an example of folders in the VMs and Templates inventory.

You can browse through these folders using the vSphere PowerCLI Inventory Provider. PowerCLI also has a set of cmdlets to work with these folders: Get-Folder, Move-Folder, New-Folder, Remove-Folder, and Set-Folder.

You can use the Get-Folder cmdlet to get a list of all of your folders:

PowerCLI C:\> Get-Folder

Or you can select specific folders by name using the following command line:

PowerCLI C:\> Get-Folder –Name "Accounting"

All folders are organized in a tree structure under the root folder. You can retrieve the root folder with:

PowerCLI C:\> Get-Folder -NoRecursion

Name                           Type
----                           ----
Datacenters...

Summary


In this chapter, you looked at the Get-Help, Get-Command, and Get-Member cmdlets. You learned how to use providers and PSDrives. You also saw how to create a calculated property. Using the raw API objects with the ExtensionData property or the Get-View cmdlet was discussed, and you looked at extending PowerCLI objects with the New-VIProperty cmdlet. At the end, you learned to work with folders and you saw how you can use the New-VIProperty cmdlet to extend the Folder object of PowerCLI with a Path property.

In the next chapter, you will learn more about working with objects in PowerCLI.

Left arrow icon Right arrow icon

What you will learn

  • Download and install PowerCLI
  • Add hosts to VMware vCenter Server
  • Configure vSphere Auto Deploy
  • Use the esxcli command from PowerCLI
  • Create OS Customization Specs
  • Monitor virtual machine performance
  • Configure distributed virtual switches and storage I/O Control
  • Enable VM and Application Monitoring
  • Manage licenses for multiple hosts to migrate them easily
  • Configure an alarm to monitor your networks virtual machines
  • Generate a goodlooking HTML report in no time

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Feb 14, 2014
Length: 374 pages
Edition :
Language : English
ISBN-13 : 9781782170174
Vendor :
VMware
Languages :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Feb 14, 2014
Length: 374 pages
Edition :
Language : English
ISBN-13 : 9781782170174
Vendor :
VMware
Languages :

Packt Subscriptions

See our plans and pricing
Modal Close icon
£16.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
£169.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just £5 each
Feature tick icon Exclusive print discounts
£234.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just £5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total £ 116.97
Troubleshooting vSphere Storage
£32.99
Learning PowerCLI for VMware VSphere
£37.99
vSphere High Performance Cookbook
£45.99
Total £ 116.97 Stars icon
Banner background image

Table of Contents

10 Chapters
Introduction to PowerCLI Chevron down icon Chevron up icon
Learning Basic PowerCLI Concepts Chevron down icon Chevron up icon
Working with Objects in PowerShell Chevron down icon Chevron up icon
Managing vSphere Hosts with PowerCLI Chevron down icon Chevron up icon
Managing Virtual Machines with PowerCLI Chevron down icon Chevron up icon
Managing Virtual Networks with PowerCLI Chevron down icon Chevron up icon
Managing Storage with PowerCLI Chevron down icon Chevron up icon
Managing High Availability and Clustering with PowerCLI Chevron down icon Chevron up icon
Managing vCenter with PowerCLI Chevron down icon Chevron up icon
Reporting with PowerCLI Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.9
(15 Ratings)
5 star 33.3%
4 star 46.7%
3 star 6.7%
2 star 6.7%
1 star 6.7%
Filter icon Filter
Top Reviews

Filter reviews by




M. Poore Mar 05, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Unless you’re new to vSphere, you’ll probably have heard about PowerCLI. You may already be using it regularly or perhaps you’ve found the occasional use for it and used one or more of the many excellent scripts that can be found on the internet. Either way, unless you’re an advanced user (or even a guru) of PowerCLI, "Learning PowerCLI” is well worth a look in my opinion. The author has posted many times on his blog with useful scripts, one-liners and tips for using PowerCLI in the past. Several times an issue that I’ve had has lead me to his blog so I was very interested to see if his knowledge and experience had translated well into book form.Although I did read through the book from cover to cover, it’s not really that sort of book. PowerCLI and Powershell are technologies that you can easily dip into when a specific need arises and I found that trying to absorb the entire contents of the book was hard-going. That shouldn’t be taken as any sort of slight against the author’s writing style, it’s just the subject matter doesn’t lend itself to being the kind of book that you can’t put down. It is, though, the kind of book that you want to pick up and learn from. I’ve been using Powershell and PowerCLI for many years and I was surprised at the number of things that I learned!People with a very strong grasp of Powershell and PowerCLI already might find that there’s a limit to what they gain from the book but beginners and intermediates alike should find that there’s plenty to take away and use.
Amazon Verified review Amazon
David Hesse Mar 15, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Ich habe mir dieses Buch in der Kindle Edition gekauft und lese es entweder in der S-Bahn auf dem Weg zur Arbeit, oder auch am Arbeitsplatz-Computer, wenn ich mal schnell einen Befehl nachschauen muss.Der Inhalt ist methodisch gut aufbereitet. Beginnend von der Installation über die erste Einrichtung bis hin zu komplexen Abfragen wird an alles gedacht und man ist auf Grund des methodisch didaktischen Aufbaus der einzelnen Kapitel und dem Bezug zur Praxis anhand von nachvollziehbaren Beispielen, niemals mit dem Inhalt überfordert und möchte das gelernte gleich ausprobieren.Ich benutze die vSphere Power CLI weniger als Deployment/Automation Tool, aber dafür mehr als Reporting-Tool, da mit mit den vielen CMD-lets eine Menge von Konfigurationsabfragen machen kann, welche sonst mühsam über den vSphere Client, oder anderen Third Party Tools extrahieren müsste um mal eben schnell einen Report an meinen Manager schicken zu können.Die vSphere Power CLI gehört neben dem vSphere CLI, welches auf Perl beruht zu den wichtigsten Werkzeugen eines jeden VMware Admins. Beide Tools ergänzen sich und haben Ihre Daseinsberechtigung. The vSphere Power CLI entwickelt sich jedoch auf Grund der wachsenden Popularität der Windows PowerShell und der immer grösser werdenden PowerShell Community dessen aktive Mitglieder auch mit neuen Snippets und eigenen Scripts zur Verbesserung und Erweiterung des Anwendungsspektrums beitragen zum Remote Management Tools Nr. 1 eines jeden VMware Administrators.Dieses Buch ist allemal die Investition Wert. Für Leute wie mich die eine zentrale Informationsquelle den verstreuten Informationen im Internet bevorzugen ist ein gut geschriebenes Buch wie dieses immer die erste Wahl.
Amazon Verified review Amazon
PowerCLI.de Apr 01, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
VMware PowerCLI is a set of PowerShell cmdlets for the administration of VMware vSphere and vCloud products.Three Weeks ago Packt Publishing released the book Learning PowerCLI. I read the book and here is my review.The authorRobert van den Nieuwendijk is an IT professional from the Netherlands. Since 2011, he writes his own blog about Microsoft PowerShell, VMware vSphere and VMware PowerCLI. In 2012 and 2013 he was awarded with the vExpert title by VMware.The audienceThe book was written for VMware vSphere administrators with an interest in automating vSphere administration. Though you will get some basic knowledge about VMware vSphere while reading this book, vSphere administration fundamentals are recommended.In my opinion, you should also bring some experience with Microsoft PowerShell and basic scripting or programming concepts.You don’t need any experience with VMware PowerCLI. The book covers everything you need to get you started.The requirementsTo run any of the commands or scripts you find in this book, you will need the following software:• Microsoft PowerShell 2.0 or higher (comes with Microsoft Windows)• VMware PowerCLI (a free product from VMware)• VMware vCenter server• VMware ESXiThe last two products are available with a free 60-day evaluation license. Of course, a full license will also do. VMware ESXi free edition instead is limited to read-only access, which is not being able to modify any settings with PowerCLI.The structureThe first chapter covers PowerCLI basics. You will learn how to install PowerCLI, connect to and disconnect from a host or vCenter server, and how to retrieve a list of your hosts or virtual machines.The next two chapters cover PowerShell and PowerCLI basics, e. g.• finding commands and getting command help• PowerShell Providers and PSDrives• creating, examine and using PowerShell objects• working with PowerCLI objects• using the PowerShell pipelineThese chapters will not only give you a basic understanding of VMware PowerCLI, but also improve your knowledge in fundamental PowerShell concepts.The following six chapters are a detailed commandline reference for the administration of hosts, virtual machines, virtual networks, storage, clustering and VMware vCenter server. You will learn which cmdlets are available, what they do, and how to use them.The final chapter is about VMware vSphere reporting and shows you how to retrieve various data from your environment and create exports and reports.ConclusionThe book is very, very detailed. That’s a good thing especially for beginners and as a reference, but probably too much information to read one chapter after another.“Learning PowerCLI” offers a great introduction to the automation of VMware vSphere. It’s not a book about how to automate your daily administration tasks. It is a book about PowerCLI concepts and cmdlets.I suggest to study the chapters 1-3 thoroughly and to use the other chapters as a reference whenever Get-Command and Get-Help do not give you enough information.If you already work with PowerShell and PowerCLI, it can help to increase your knowledge. I’ve been using both for years and got a lot of new information and ideas from this book.
Amazon Verified review Amazon
Marco C. Oct 13, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
An essential guide, for beginners but also with a lot of insights into inner aspects of Powercli scripting.
Amazon Verified review Amazon
Hernán Mar 14, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
The first chapter explains how to download and install PowerCLI then move on to issues like change policy tool execution and logging in to servers and how to avoid annoying but always useful warnings about certificates. Also makes a journey on the use of credentials, filtering objects and as inventories and get listings from servers to which we connect.In chapter two usage is explained cmdlets , which are the proper instructions with which we can perform all tasks with PowerCLI. It looks like you can use arrays and hash tables, the use of properties and working with folders vSphere.The third chapter explores the use of PowerShell and working with objects, while in chapter four and five, each complete expatiate on the management of hosts and virtual machines, explaining clearly as restarting services, create, modify and remove virtual machines, manage storage controllers, network and upgrade the environment. It also explains how you can create snapshots and run guest operating system commands on the virtual machines.Chapter six is ​​entirely dedicated to network management in VMware environments, focusing on the standard virtual switches and distributed, as well as management VLANs and NIOC. Chapter seven focuses on his side's exclusive virtual storage management, dealing with datastores, policies pathing, and storage clusters as absolutely everything, can be controlled and managed from PowerCLI. The eighth chapter deals with clusters of tasks and HA. The ninth and penultimate is about showing how to use PowerCLI to manage vCenter Server and all tasks VMware administrator requires. And finally, the tenth chapter explains how to harness the power and versatility of PowerCLI to generate useful reports and metrics that serve to conduct a detailed environmental analysis.In conclusion, is an excelent guide to inmerse into PowerCLI world.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.