Whatever backup solution you use to backup your virtual infrastructure with, you may sometimes end up with VM snapshots that need to be cleaned up. After a backup failure alert, I use the following PowerCLI one-liners to quickly identify and remove snapshots left behind (by say Netapp SMVI).
Get-VM | Get-Snapshot | Where-Object {$\_.Name -like 'smvi\*'} | ft VM,Name,Created -AutoSize Get-VM | Get-Snapshot | Where-Object {$\_.Name -like 'smvi\*'} | Remove-Snapshot -RunAsync -Confirm:$false Recently I had an instance where post a backup failure the snapshot failed to remove with the error Unable to communicate with the remote host, since it is disconnected.
When using the PowerShell ISE , similar to other scripting editors, you have access to what are known as ‘code snippets’. These are quick start ways to generate frequently used code, for instance if there is something you use regularly and can never remember the syntax for, or maybe it is too long to be practical to remember it.
PowerShell ships with some default snippets and it is also possible to add some custom snippets of your own.
Recently I’ve been writing a lot of Puppet modules. Usually this starts for me by creating a folder structure which typically looks something along the lines of this:
dir | tree Creating this each time via Explorer soon became pretty tedious, so I put together the following function New-PuppetModule. This is along the lines of the puppet command to generate a module structue:
puppet module generate name By default New-PuppetModule will create the top level module folder, a manifests folder and a blank init.
Update 30/10/2013: There’s an updated post on the PowerShell Team Blog which now describes this situation with .NET 4.5 as a pre-requisite in more detail.
-———————————————————————————————-
PowerShell 4.0 which shipped as part of Windows Server 2012 R2 and Windows 8.1 is now available for down-level Windows versions via the downloadable Windows Management Framework 4.0.
WMF 4.0 contains updated versions of the following features:
Windows PowerShell Windows PowerShell Integrated Scripting Environment (ISE) Windows PowerShell Web Services (Management OData IIS Extension) Windows Remote Management (WinRM) Windows Management Infrastructure (WMI)
The agenda for this year’s UKVMUG has been published and a pretty fine line up it looks too. What’s really great is that during each section of sessions, there’s a community slot with real world info from people working with VMware technologies at the coalface. You’ll be able to pick sessions from @sammcgeown @maishsk @etherealmind @rickyelqasem and me. I’ll be talking about some of my experiences of PowerCLI automation in the field and examples of how to break your code down to make it more flexible to use in different scenarios.
The other day I noticed some comments on Twitter around the time taken to install VMware vCloud Automation Center 5.2
Being of curious nature I decided to check it out further and in doing so discovered this extensive installation guide from Jad El-Zein. Seeing as a lot of the pre-requisites are installing Windows Roles / Features and configuring IIS, I figured this would make a good candidate for some PowerShell work and might save you some time if you need to do this yourself.
Having recently enabled Storage DRS in a vSphere 5.1 environment we began to see a lot of the following errors in vCenter:
The device or operation specified at index ‘x’ is not supported for the current virtual machine version ‘vmx-04’. A minimum version of ‘vmx-06’ is required for this operation to succeed
The host(s) running the VM(s) in question contained the error matched in this VMware KB article:
[2009-07-10 14:13:41.632 F638BB90 info ‘vm:/vmfs/volumes/4a56e6c2-9319e3df-f1af-001e0bea4030/RVHOLS029/RVHOLS029.
This one tripped me up earlier in the week, so thought it was worth sharing in case you hit the same issue sometime. In PowerShell v2 and earlier when using Get-Credential to save credentials into a variable and NOT using a full Windows domain credential, e.g. something like:
instead of a more Windows style credential:
then the resultant stored credential prepends a \ in front of the username:
$cred = Get-Credential PS C:\\> $cred UserName Password -------- -------- \\root System.
I recently experienced an issue adding a vSphere 5.1 host to vCenter while using the Add-VMHost cmdlet in PowerCLI. I’m pretty sure the same problem would have occured if I was using the GUI, but this work was for part of some automated deployment work.
On a freshly baked ESXi 5.1 install one of the first tasks is to get it into vCenter. However, this was failing with what initially appeared to be a license issue, despite there being plenty of available licenses.
A question I’ve fielded now and again in the past, “Can I use PowerShell to access Linux servers?”. Among others, there were a few answers I could give of varying degrees of usefulness depending on the requirements:
Use the command line tool plink.exe Look at OMI I was recently asked this again at my current workplace and discovered a project I hadn’t seen previously, a PowerShell module based on the SSH.