Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Learning PowerCLI
Learning PowerCLI

Learning PowerCLI: A comprehensive guide on PowerCLI , Second Edition

Arrow left icon
Profile Icon van den Nieuwendijk
Arrow right icon
₱579.99 ₱2245.99
Full star icon Full star icon Full star icon Full star icon Full star icon 5 (1 Ratings)
eBook Feb 2017 562 pages 2nd Edition
eBook
₱579.99 ₱2245.99
Paperback
₱2806.99
Subscription
Free Trial
Arrow left icon
Profile Icon van den Nieuwendijk
Arrow right icon
₱579.99 ₱2245.99
Full star icon Full star icon Full star icon Full star icon Full star icon 5 (1 Ratings)
eBook Feb 2017 562 pages 2nd Edition
eBook
₱579.99 ₱2245.99
Paperback
₱2806.99
Subscription
Free Trial
eBook
₱579.99 ₱2245.99
Paperback
₱2806.99
Subscription
Free Trial

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

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 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 the commands that are installed on your computer. The Get-Command cmdlet has the following syntax. The first parameter set is named CmdletSet:

Get-Command [[-Name] <String[]>] [[-ArgumentList] <Object[]>] [-All] [-CommandType {Alias | Function | Filter | Cmdlet | ExternalScript | Application | Script | Workflow | Configuration | All}] [-FullyQualifiedModule <ModuleSpecification[]>] [-ListImported] [-Module <String[]>] [-ParameterName <String[]>] [-ParameterType <PSTypeName[]>] [-ShowCommandInfo] [-Syntax] [-TotalCount <Int32>] [<CommonParameters>]

The second parameter set is named AllCommandSet:

Get-Command [[-ArgumentList]...

Using providers and PSDrives

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

Using providers

A PowerShell provider is a piece of software that makes datastores 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 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 the cmdlets with these nouns:

PowerCLI C:> Get-Command -Noun Item,ChildItem,Content,ItemProperty |
Format-Table -AutoSize

The preceding command gives the following output:

CommandType Name                Version Source
----------- ----                ------- ------
Cmdlet...

Using arrays and hash tables

In PowerCLI, you can create a list of objects. For example, red, white, and blue is a list of strings. In PowerShell, a list of terms is named 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...

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 your virtual machines, run the following command:

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

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 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 the commands that are installed on your computer. The Get-Command cmdlet has the following syntax. The first parameter set is named CmdletSet:

Get-Command [[-Name] <String[]>] [[-ArgumentList] <Object[]>] [-All] [-CommandType {Alias | Function | Filter | Cmdlet | ExternalScript | Application | Script | Workflow | Configuration | All}] [-FullyQualifiedModule <ModuleSpecification[]>] [-ListImported] [-Module <String[]>] [-ParameterName <String[]>] [-ParameterType <PSTypeName[]>] [-ShowCommandInfo] [-Syntax] [-TotalCount <Int32>] [<CommonParameters>]

The second parameter set is named AllCommandSet:

Get-Command [[-ArgumentList]...

Using providers and PSDrives


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

Using providers

A PowerShell provider is a piece of software that makes datastores 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 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 the cmdlets with these nouns:

PowerCLI C:> Get-Command -Noun Item,ChildItem,Content,ItemProperty |
Format-Table -AutoSize

The preceding command gives the following output:

CommandType Name                Version Source
----------- ----                ------- ------
Cmdlet...

Using arrays and hash tables


In PowerCLI, you can create a list of objects. For example, red, white, and blue is a list of strings. In PowerShell, a list of terms is named 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 your virtual machines, run the following command:

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

Key benefits

  • This is first book on the market that will enlighten you on the latest version of PowerCLI and how to implement it
  • Effectively manage virtual machines, networks, and reports with the latest features of PowerCLI
  • A comprehensive and practical book on automating VMware vSphere

Description

VMware vSphere PowerCLI, a free extension to Microsoft Windows PowerShell, enables you to automate the management of a VMware vSphere or vCloud environment. This book will show you how to automate your tasks and make your job easier. Starting with an introduction to the basics of PowerCLI, the book will teach you how to manage your vSphere and vCloud infrastructure from the command line. To help you manage a vSphere host overall, you will learn how to manage vSphere ESXi hosts, host profiles, host services, host firewall, and deploy and upgrade ESXi hosts using Image Builder and Auto Deploy. The next chapter will not only teach you how to create datastore and datastore clusters, but you’ll also work with profile-driven and policy-based storage to manage your storage. To create a disaster recovery solution and retrieve information from vRealize Operations, you will learn how to use Site Recovery Manager and vRealize Operations respectively. Towards the end, you’ll see how to use the REST APIs from PowerShell to manage NSX and vRealize Automation and create patch baselines, scan hosts against the baselines for missing patches, and re-mediate hosts. By the end of the book, you will be capable of using the best tool to automate the management and configuration of VMware vSphere.

Who is this book for?

This book is ideal for you if you want to learn how to automate your VMware vSphere or vCloud infrastructure by getting the most out of PowerCLI. It’s assumed that you have some experience in administrating a vSphere or vCloud environment. Knowledge of Microsoft’s Windows PowerShell is not a prerequisite.

What you will learn

  • • Explore PowerShell and PowerCLI cmdlets and their output objects
  • • See how to manage virtual machines and work with virtual networks
  • • Manage vCloud Director from PowerCLI
  • • Use Site Recovery Manager from PowerCLI to create a disaster recovery solution
  • • Manage NSX and vRealize Automation using REST API with PowerCLI
  • • Create and configure vSphere HA and DRS clusters
  • • Use vSphere Update Manager with PowerCLI to create patch baselines and scan hosts
  • • Explore reporting techniques to retrieve log files

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Feb 23, 2017
Length: 562 pages
Edition : 2nd
Language : English
ISBN-13 : 9781786466921
Vendor :
VMware
Tools :

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 23, 2017
Length: 562 pages
Edition : 2nd
Language : English
ISBN-13 : 9781786466921
Vendor :
VMware
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.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
$199.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 ₱260 each
Feature tick icon Exclusive print discounts
$279.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 ₱260 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 8,726.97
Learning PowerCLI
₱2806.99
Mastering PowerCLI
₱3112.99
Mastering VMware vSphere 6.5
₱2806.99
Total 8,726.97 Stars icon
Banner background image

Table of Contents

15 Chapters
1. Introduction to PowerCLI Chevron down icon Chevron up icon
2. Learning Basic PowerCLI Concepts Chevron down icon Chevron up icon
3. Working with Objects in PowerShell Chevron down icon Chevron up icon
4. Managing vSphere Hosts with PowerCLI Chevron down icon Chevron up icon
5. Managing Virtual Machines with PowerCLI Chevron down icon Chevron up icon
6. Managing Virtual Networks with PowerCLI Chevron down icon Chevron up icon
7. Managing Storage Chevron down icon Chevron up icon
8. Managing High Availability and Clustering Chevron down icon Chevron up icon
9. Managing vCenter Server Chevron down icon Chevron up icon
10. Patching ESXi Hosts and Upgrading Virtual Machines Chevron down icon Chevron up icon
11. Managing VMware vCloud Director and vCloud Air Chevron down icon Chevron up icon
12. Using Site Recovery Manager Chevron down icon Chevron up icon
13. Using vRealize Operations Manager Chevron down icon Chevron up icon
14. Using REST API to manage NSX and vRealize Automation Chevron down icon Chevron up icon
15. Reporting with PowerCLI Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Full star icon Full star icon 5
(1 Ratings)
5 star 100%
4 star 0%
3 star 0%
2 star 0%
1 star 0%
Kim Bottu Feb 28, 2017
Full star icon Full star icon Full star icon Full star icon Full star icon 5
If you are new to PowerCLI and you have no idea how to start learning it, a technical book for beginners such as this one will be very welcome.I remember that when I started looking into PowerCLI, I devoured articles on the internet and books such as this one. The combination of both resources thaught me the basics I still use and welcome every day.What this book does not do is teach you litterally everything about PowerCLI and how to use it. However it will get you started on PowerCLI using clear examples and exersizes. What better way than learning a new skillset than by actually putting it to use?Kim, technical reviewer for Learning PowerCLI 2nd edition.
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.