powershell

Automate vRealize Automation with PowerShell: Introducing PowervRA

While putting together the PowerCLI book 2nd Edition we initially included in the proposed Table of Contents a chapter on vRealize Automation. However, it was fairly apparent that at that time (early 2015) there wasn’t a lot which could be done to fill out the chapter with good content. Firstly, most of the relevant content would be included in the vRO chapter, i.e. use vRA to call a vRO workflow to run PowerShell scripts.

Count the Number of Lines in Multiple Text Files with PowerShell

While working on developing a PowerShell module, I was curious to find out the number of lines of code within all of the functions that comprise the module. I didn’t realise that the Measure-Object cmdlet has a Line parameter. Consequently, it is a trivial task since the module is made up of a number of text files.

PowerCLI Book 2nd Edition is Now Available!

…..well in Kindle format anyway :-) The paperback version will be available on 11th January in the US and 12th January in the UK and according to the publisher, apparently in book shops from the 19th January. Seriously, if you actually see one in a book shop then please send me a photo, since I’ve not seen that happen outside of a VMworld. With my fellow authors, Luc Dekens, Glenn Sizemore, Brian Graf, Andrew Sullivan and Matt Boren, we spent the best part of 2015 putting this book together.

Star Wars Episode IV in ASCII in PowerShell

I saw this post the other day about displaying Star Wars Episode IV in ASCII in vRO and thought it would be fun to see it in a PowerShell console. Make sure you have the telnet client installed on your workstation then simply fire off this command: telnet towel.blinkenlights.nl

PowerShell Quick Tip: Testing JSON Syntax

I’ve been working a lot with JSON files recently and quite regularly I need to update their content for testing of code changes. While editing the files I want to make sure I don’t introduce an error by making a syntax error in the JSON file. I’ve been using a quick way in PowerShell to test the JSON is clean and if not, to point me at the line in the file where there is a problem.

Onyx for the vSphere Web Client

The original Project Onyx (also here) was a VMware Fling which intercepted calls between the C# vSphere client and vCenter and could translate things you did in the GUI client to code in your choice of languages; SOAP, C#, PowerCLI, and JavaScript. This was really useful if say a thing you needed to do was not yet covered by a PowerCLI cmdlet, or you wanted to try and make it faster by using Get-View, or you didn’t know how to code it in JavaScript for vRO.

PowerShell Module for the Brickset API

Update 18/01/2021: See this post for details on an updated version of this module, parts of the below may now be out of date. Brickset.com is one of my favourite sites for finding info about Lego sets and keeping up-to-date with Lego news. I noticed recently that they had an API so I thought I would check it out. I posted a while back on how to do some similar stuff with other websites, but some of the functionality on those websites is no longer available.

PowerShell: Default Value of [Int]$a is 0

I didn’t realise until yesterday that the default value of a variable using the [int] type had a default value of 0, e.g \[Int\]$a So what’s the big deal? Say you have a function as follows: function Test-DefaultInt { Param ( \[Int\]$a, \[Int\]$b, \[Int\]$c ) "a is $a" "b is $b" "c is $c" } and run it like so Test-DefaultInt -a 5 -b 6 -c 7 Test-DefaultInt -a 5 -b 6 You get the following results:

PowerShell Requires -Modules: ModuleVersion "Argument must be constant"

I was looking to make use of a PowerShell feature which prevents a script from running without the required elements. Detailed here (about_Requires) there are examples for requiring specific versions of PowerShell, snap-ins and modules, and administrative rights. In particular I was looking at the modules example given in the documentation: #Requires -Modules PSWorkflow, @{ModuleName="PSScheduledJob";ModuleVersion=1.0.0.0} Unfortunately, using this example as is given generates an error Argument must be constant: C:\\Scripts\\Scratch> .

PowerCLITools Community Module: Now on GitHub

Over the last few years I have built up a number of functions to use alongside the out of the box functionality in PowerCLI. I’ve posted some of the content before on this blog, but have at last got round to publishing all of the content that I am able to share, in a module available on GitHub - I’ve named it the PowerCLITools Community Module in the hope that some others might want to contribute content to it or improve what I have already put together.