New book – Learning PowerCLI

Learning PowerCLI Book CoverI am verry happy to announce that my first book Learning PowerCLI has been published today by Packt Publishing. This book is written for VMware vSphere administrators who want to automate their
vSphere environment using PowerCLI. Learning PowerCLI is written in a friendly and practical style with a focus on getting you started and automating daily tasks quickly and efficiently. If you manage or administrate a vSphere environment, and want to make that easier and more efficient, then this book is for you! It is assumed that you have at least a basic knowledge of VMware vSphere. If you are not a vSphere administrator, but you are interested in learning more about PowerCLI, then this book will also give you some basic knowledge of vSphere. Read more of this post

Advertisement

Book “Learning PowerCLI” is now available for pre-order

0167EN_mockupcover_normalSome of you may have noticed that I have not been blogging very much lately. This is because I am now writing my first book “Learning PowerCLI”.

This book is aimed at beginning and advanced PowerCLI users and will help you to automate your VMware vSphere environment including hosts, clusters, storage, virtual machines, networks and vCenter Server. The book teaches you how to use old and new VMware vSphere features like Datastore Clusters, the vSphere Distributed Switch, Host Profiles, Image Builder and Autodeploy, Storage I/O Control and much more using PowerCLI.

The expected release date of the “Learning PowerCLI” book is November 2013.

The “Learning PowerCLI” book is available for pre-order at http://www.packtpub.com/learning-powercli/book.

PowerCLI Get-VICommand function error repaired

PowerCLI logoOn my PC (Windows 8 Pro, Windows PowerShell 3 and VMware vSphere PowerCLI 5.1 Release 2) there is a very annoying problem with the Get-VICommand function. If I use this function without specifying the name of a cmdlet to search for, then I get an “Object reference not set to an instance of an object” error message:

PowerCLI C:\users\robert> Get-VICommand
get-command : Object reference not set to an instance of an object.
At C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1:68 char:3
+   get-command -pssnapin VMware.* -Name $Name
+   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Get-Command], NullReferenceException
    + FullyQualifiedErrorId : System.NullReferenceException,Microsoft.PowerShell.Commands.GetCommandCommand

Listing 1. Get-VICommand error message with PowerShell 3.
Read more of this post

Get VMware vCenter Scheduled Tasks with PowerCLI

PowerCLI logoVMware vSphere PowerCLI is missing cmdlets to work with VMware vCenter Scheduled Tasks. In a series of blog posts I will show you some PowerShell advanced functions that you can use to work with vCenter Scheduled Tasks. The first function is Get-VCScheduledTask. You can use this function to retrieve one or more scheduled tasks from your vCenter Server. Read more of this post

Use PowerCLI to consolidate snapshots in vSphere 5

PowerCLI logoIn vSphere 5 a virtual machine can have a “Virtual machine disks consolidation is needed” Configuration Issue warning in the Summary tab. How can you use PowerCLI to see which virtual machines have this warning? And how can you automate the consolidation of the virtual machine’s disks? Read more of this post

How to list all the PowerCLI ESXCLI commands

PowerCLI logoLast week there was a question in the VMware VMTN Communities VMware vSphere PowerCLI forum from Papires who asked how you can convert the ESXCLI command ‘esxcli storage vmfs snapshot mount -l “DATASTORE”‘ into a PowerCLI command. I had not done very much with ESXCLI in PowerCLI, but I knew that it was something like ‘$esxcli.storage.vmfs.snapshot.mount’. However I was struggling with the ‘-l “DATASTORE”‘ part.

There is not much documentation available about the ESXCLI commands in PowerCLI. And also a search in Google did not help me very much. Finally I found the right answer using the PowerShell Get-Member cmdlet. Read more of this post

Use PowerCLI to find the datastore from a disk name

PowerCLI logoRecently we get vSphere alarms in our environment that say for instance:

“[VMware vCenter – Alarm Host error] Issue detected on host in datastore: ScsiDeviceIO: 2368: Failed write command to write-quiesced partition naa.600a0b8000111155000021c53f97784e:1 (42:01:04:07.994 cpu7:5191)”

There seems to be a problem on a partition. But which datastore is on this partition? We can use PowerCLI to find the datastore involved. Read more of this post

Function to speed-up the execution of the first PowerCLI cmdlet

PowerCLI logo
Last year there was a post on the PowerCLI Team blog called How to speed-up the execution of the first PowerCLI cmdlet. That post showed commands you need to execute to pre-compile some of the PowerCLI code to prevent this from being done in every PowerCLI session.

Running these commands will speed-up the execution of the first PowerCLI cmdlet you run in your session. The blog post was made before PowerCLI 5.0 was released and didn’t show the commands to speed-up PowerCLI 5.0. Later there was a post at the vNugglets blog Speed Up First PowerCLI 5 cmdlet — Precompile XMLSerializers that shows the commands needed for PowerCLI 5.0.

But what happens when PowerCLI 5.1 or 6.0 is released? Of course we can try to find the new commands needed to speed-up PowerCLI every time a new version is released. But would it not be easier if we have a function that will do this for you?

The Install-PowerCLIXmlSerializer function presented in this post will show you a PowerShell function that you need to run once after you install a new PowerCLI version to speed-up the execution of the first cmdlet every time you run PowerCLI. Read more of this post

PowerCLI 5.0.1 Connect-VIServer repaired

PowerCLI logo
PowerCLI up to version 5.0.1 showed the connected servers in the title bar of the window. I found this very handy. Unfortunately though VMware has removed this feature in version 5.0.1. In this blogpost I present you a script that returns this feature. Read more of this post

Speed up your PowerCLI cmdlet typing with aliases

PowerCLI logoIf you are like me and managing a VMware vSphere environment is your daily job, and you want to automate your job as much as possible, you probably always have a PowerCLI session open. PowerCLI cmdlet names are sometimes pretty long. Of course you can use tab completion. But wouldn’t it be nice if you had short aliases for the PowerCLI cmdlets? Read more of this post