powershell

Automation Station at the UKVMUG 2012

How do you provision, manage and decommission your (sprawling) infrastructure? Running around fighting fires while interesting project work falls by the wayside? Spending long evenings and weekends carrying out maintenance tasks while others are tweeting pictures of what fun they’re having in their spare time? Hiding from the bosses while they hunt you down to deploy a private cloud before Friday afternoon? Or even just figuring out what the heck infrastructure you have got and what underlying issues can you report on….

Install PowerCLI 5.1 in Windows 8

I don’t believe that PowerCLI 5.1 is yet officially supported on Windows 8, however that’s where I wanted to run it. While carrying out the installation I hit this issue, i.e. .NET Framework 2.0 was not installed as a pre-requisite. This is because PowerShell 3.0 on Windows 8 uses .NET 4 and no longer has .NET 2.0 as a requirement. To install .NET Framework 2.0 in Windows 8 you need to turn on .

PowerShell v3 - New -in Operator

Hidden away amongst some of the new language features in PowerShell v3 are two new operators: -in and -notin. Previously you could use -contains, say in an example like the following: does the variable $fruits contain the string ‘Apple’? $fruits = 'Apple','Orange','Pear' $fruits -contains 'Apple' $fruits -contains 'Banana' There’s nothing wrong with this approach, but in many examples for me it seemed to be the wrong way around from that I was naturally thinking: is the string ‘Apple’ in the variable $fruits?

Filtering XML Child Elements in PowerShell

Recently I was working with some XML documents along the lines of the following. Each set of data had some common elements, Name and Description and other elements based around a pattern, Filepathx. [xml] [/xml] I needed to check the path for any of these that were present in each dataset. Working with XML files in PowerShell is pretty straightforward. For instance to work with the above file you could start with:

Multiple Values in a PowerShell Switch Statement

I’ve needed to use multiple values in a PowerShell Switch statement a number of times recently and can never quite remember the syntax, so thought it would be useful to get it down on paper so to speak. In PowerShell you can use a switch statement instead of using multiple if statements, e.g. $a = 3 switch ($a) { 1 {"It is one."} 2 {"It is two."} 3 {"It is three.

PowerShell: Get-Process -ComputerName localhost, fails with 'Couldn't connect to remote machine'

This issue came up during my PowerShell class today and since I couldn’t find any information about it, I thought it was worth a quick post. There aren’t many practical reasons for running a cmdlet with the ComputerName parameter and localhost as the computer other than for demo or training purposes when you may not have a remote machine to test against. Running the below may result in the error ‘Couldn’t connect to remote machine’

Get-Scripting Episode 31 - Talking PowerShell v3 with Jonathan Noble

With the imminent release of Windows 8 and Server 2012, it’s definitely time to start preparing for PowerShell v3 which will ship as part of those releases. We recorded the latest edition of the Get-Scripting Podcast with PowerShell MVP Jonathan Noble and specifically focus on a number of topics worth checking out to get you up to speed with v3. Jonathan provides an overview on his blog of the topics we covered and some useful links.

Checking 32bit PowerShell Snapins from 64bit PowerShell

In PowerShell you use Get-PSSnapin to view available third-party snapins for PowerShell on your system. However, some snapins may ship versions in 64bit, 32bit or both. If you install a 32bit snapin on a 64bit machine and then run Get-PSSnapin from 64bit PowerShell, only 64bit snapins will be displayed - which can lead to some initial confusion. Consider the following example of two 32bit snapins installed on a 64bit machine. 64bit PowerShell has no knowledge of them, but 32bit does.

Automate MSI Installations with PowerShell

The following is a PowerShell wrapper for msiexec.exe that enables you to automate the installation of MSI packages. You will see in the code that I picked certain msiexec options that were required for the particular need I had, such as quiet install (/qn). If you need other options, simply add or remove them to the arguments section. The function takes pipeline input, so to install an msi you can do the following