Category: PowerShell
If you have ever managed a VMware environment that contains virtual machines with RDM (Raw Device Mapping) disks then you will know it is a pain to track and manage RDMs, especially when trying to distinguish which VM has a specific RDM disk attached or if the RDM is still attached to a VM. You will also know that it is nearly impossible to find an RDM (and the corresponding VM) based on RDM’s LUN ID.
To ease the management burden of RDMs, I have written a script to search for a specific RDM by LUN ID or alternatively to get a list of all RDMs, their LUN ID, Capacity, Disk Identifier and the VM they are attached to. Below is the script and all of the details you need to get it up and running in your environment…
To coincide with my new PowerShell Logging Module, I have also updated my PowerCLI Script Template to now use the PSLogging module as opposed to my original PowerShell_Logging function library.
This template is based on my PowerShell Script Template Version 2, but has been modified for use with PowerCLI so that you can easily create scripts and solutions to automate your VMware world!
Below is everything you need to know on the PowerCLI template, as well as the template itself…
To coincide with my new PowerShell Logging Module, I have updated my PowerShell Script Template to now use the PSLogging module as opposed to my original PowerShell_Logging function library.
The article below introduces you to the new PowerShell Script Template version 2 and shows you how to implement it in your scripts and how to create PowerShell log files.
Sometime back in 2011 when I first started using PowerShell, I developed some standard functions to handle the creating and management of log files for my PowerShell scripts. These functions were stored in a file called Logging_Functions.ps1 and I would simply dot source them into my script to be able to use them.
I posted them on 9to5IT PowerShell: How to easily create log files for your scripts and since then, to my surprise, they have been well received by many people, and hence the post has become quite a popular one. Recently one of the users emailed me and made a suggestion to convert them into a PowerShell Module.
That got me thinking…. so I have made a number of improvements to the PowerShell logging functions and have now made them available as a PowerShell Logging module. Available right here, below….
At some point during your PowerShelling career you will need to test if “something” is found (or not found) within a certain object. I find that I am usually faced with this situation when I am testing if a string “contains” a value or not.
At this point, I am always confused as to which comparison operator to use. From a logical language perspective I always feel like -contains
is the way to go, but then I remember that might not be the correct choice.
To put this issue to bed once and for all (at least for myself), here is a summary of when to use -like
and when to use -contains
.
Important Update
As of September 2015, I have released version 2 of my PowerCLI Script Template, which includes a number of improvements over this version, in particular the use of the new PSLogging PowerShell module that significantly improves the creation and management of log files. This version of the template is no longer supported or maintained, so please upgrade to the new version today!
Version 2 of the template is available here – PowerCLI Script Template v2.
A while a go I posted up my PowerShell Script Template which turned out to be pretty popular with fellow PowerShellers.
I recently create another slightly modified template when working with PowerCLI, so I thought I would share it here. Here is my PowerCLI Script Template to be used for all your VMware scripts…
This is a quick article on how to send an email with PowerShell. The way I have done this is that I have created a Send-Email PowerShell function which can then be added to your function library and dot sourced in your PowerShell scripts.
Alternatively you could just copy paste this function directly into your script and call it from there. Either way, it is simple and it works. Plus you can send both plain-text and HTML emails. So here it is…