Optimize-VMwarePKS

A guest post

Over the last couple of weeks, it has been my great pleasure to assist Chip Zoller in writing a VMware PowerCLI script, named Optimize-VMwarePKS. This script helps organise your PKS deployment at three levels: folders, tags and DRS rules, including functionality to run a clean up.

VMware PKS

The following post by Chip describes the function in greater detail, and shows how you can use it.

This post also appears on the Sovereign Systems website as Optimize-VMwarePKS: A PowerShell Script for All Your VMware PKS Deployment Needs.

Take it away Chip.

Continue reading Optimize-VMwarePKS

DSCR and Pester testing

In my previous post DSCR for VMware and you! I described the open source project that was started to develop DSC resources for vSphere (DSCR). One of the requirements for contributing, is that you provide Unit and Integration Pester tests for any new DSC resource you contribute to DSCR.

The vSphere environment and VMware PowerCLI have some peculiarities that will require you to use some specific Pester techniques to write these Pester tests. This post should help you understand how this done. This is not intended as a Pester course, there are other, and better, resources for that.

Continue reading DSCR and Pester testing

DSCR for VMware and you!

On December 13th 2018 the PowerCLI Team provided us with an early end-of-year present. The Desired State Configuration Resources (DSCR) for VMware are published, and they are open sourced!
If you missed the announcement, hold what you are doing, and go read the VMware PowerCLI blog post Getting Started with Desired State Configuration Resources for VMware right now!

The next question on your mind is probably “How can I contribute?“. Well, with the correct tools and some VMware PowerCLI knowledge, it turns out that this is not too difficult. What follows is my first attempt at contributing to the Desired State Configuration Resources for VMware.

Continue reading DSCR for VMware and you!

Deploy Photon 2.0 – Part 2

In Deploy Photon 2.0 – Part 1, we showed how to create a Template with the Photon 2.0 guest OS. In Part 2 we will introduce the New-PhotonVM function, which allows to create one or more VMs, based on the template created in Part 1.

The basic concept for the New-PhotonVM function is the same as for the New-PhotonTemplate function. The configuration for the VMs is driven by a JSON file that is passed as an argument to the function.

Continue reading Deploy Photon 2.0 – Part 2

Deploy Photon 2.0 – Part 1

Photon 2.0 is definitely a guest OS that is useful in a VMware vSphere environment. It is light-weight, easy to manage, security hardened and comes with the Docker daemon. 
That last feature makes it an ideal environment to explore new applications, isolated from your live platforms. As an example, quite a few of us got to know PowerShell Core with VMware PowerCLI, while running it in a Docker container, well shielded from our other platforms.

There are numerous articles and blog posts that describe how set up a Photon 2.0 VM, but most of these use the ovftool or the vSphere Web Client to install it. Followed by quite of a bit of editing config files, to have your Photon 2.0 VM running the way you prefer it.
With the latest version of my Invoke-VMScriptPlus function, you can now automate this entire process, the SDDC way! 

 

Update August 21st 2018

  • Added “reboot” action
  • Added optional Environment variables for the customisation scripts
  • Added Folder field for template destination

Continue reading Deploy Photon 2.0 – Part 1

Message to all users, and their reply

Before you need to reboot a VM, or do some destructive maintenance on there, it is a good practice to at least tell the user(s) of that VM what is going to happen. But how do you address the users of a VM? They can be connected to a console (local) or via a RDP session (remote). And how do you get their reply back?

 

Exactly such a question appeared in the VMTN PowerCLI Community recently. And after some digging, it seems that is possible through a PowerShell script that uses the Remote Desktop Services API, provided through the wtsapi32.dll. Note that the VMs we are looking at, all are running a Windows guest OS.

Continue reading Message to all users, and their reply

Invoke-VMScriptPlus v2

The ability to execute scripts inside the guest OS of your VMs, is definitely one of the more useful cmdlets available in VMware PowerCLI. A year ago I published the first version of my Invoke-VMScriptPlus function to solve some of the issues the Invoke-VMScript cmdlet has in my opinion.
That function allowed you to run multi-line scripts in a Linux guest OS on your VMs. It also allowed you to use she-bang lines, to indicate which interpreter your script had to run in (bash, perl, python, nodejs, php…). Another handy feature was that you could use Linux here-documents in your scripts.

With the introduction of PowerShell Core (aka PowerShell v6), the lack of support for any Guest OS of the Windows family became obvious. Prompted by a recent thread in the VMTN PowerCLI Community, I decided it was time to publish a new version of my Invoke-VMScriptPlus function.

 

Update August 21st 2018

  • Added ScriptEnvironment

Continue reading Invoke-VMScriptPlus v2

PowerCLI, REST API and a sample module for Tag management

As most of you might know by now, VMware is moving away from SOAP and going to REST API.

Is this something you should know about? Yes, you should!

In a two-part article on TechGenix, I wrote down my thoughts and observations on REST API. The article goes into what this move towards the REST API might mean for you as a scripter/administrator.

 

Since an article on coding, without a coding example doesn’t make much sense, I added a module, named rCisTag on the PowerCLI Examples repository.

Articles

Enjoy reading Part 1, Understanding the VMware REST API interface!

and Part 2, SOAP vs REST for performing tasks in VMware environments.

Search VMTN with REST API

REST API are (nearly) everywhere! VMware’s VMTN website is no exception. I already did a post on Automate Your VMTN Search, but that was entirely based on constructing URI and interpreting the returned webpages. For the occasion of the PowerCLI’s 10th Birthday session at VMworld, I wanted to produce some InfoGraphs on the PowerCLI Community. For those InfoGraphs I needed to harvest data from said VMTN Community, and I looked for a better way to do this. That is where the REST API offered by the Jive software, om which the VMTN website is hosted, came in handy.

The functions I ended up with, are also a good example of how easy it is to consume REST API through PowerShell. And they also show how the basic techniques to work with REST API can be reused. Check out my VMTNRest repo.

Continue reading Search VMTN with REST API

vSphere Permission cleanup

Your vSphere environment is a living environment. Inventory objects are created and removed all the time. Together with these inventory objects there are often security permissions that come along. Team X needs Power User access for all VMs in folder Project-X. But the life-cycle management of these permissions is often not as fluent as your VM life cycle management. There is no built in permission cleanup method.

As a result, old permissions might be left behind, and what is worse, redundant permissions might be present. This doesn’t make the task of investigating “Who can do what?” in your vSphere environment any easier.

With the help of the function in this post you can now get rid of all these redundant permissions!

Continue reading vSphere Permission cleanup