I see this question often: how can I pass a parameter value for a PSCredential that might be a credential object or it might be a user name? In the past I’ve used code like this: begin { Write-Verbose -Message “Starting $($myinvocation.mycommand)” write-verbose -Message “Using volume $($volume.toUpper())” #convert credential to a PSCredential if a string…
Friday Fun: Get Next Available Drive Letter
A few days ago I saw on question, I think on Facebook, about using PowerShell to find the next available drive letter that could be used for mapping a network drive. Before I show you my approach, let me state that if you need to map a drive in PowerShell for use only within your…
Try and Catch Me If You Can
In looking at entries in this year’s Scripting Games, as well as posts I see in PowerShell forums, I thought I’d post a short guide to properly using Try/Catch. This is the way I think it should be used. Let’s start with a Try/Catch block that might look ok. Try { Get-Service Foo } Catch…
Pipeline Power
Last week I came across a blog post that had a decent example using PowerShell and PowerCLI to get the disk location for all virtual machines. The posted code works and does display the information you might be after. $myVMs = get-vm foreach($vm in $myVMs){ $myDisks = @($vm | get-harddisk) foreach ($disk in $myDisks) {…
Create an HTML PowerShell Help Page
Yesterday I posted an article about getting the online url for a cmdlet help topic. Today I want to demonstrate how we might take advantage of this piece of information. Since the link is already in the form of a URL, wouldn’t it make sense to put this in an HTML document? At first glance,…
Get Cmdlet Help URL
I was toying around with PowerShell help this morning and as usually happens one thing leads to another. When you run Get-Help, or use the wrapper function Help, you are actually getting an object: MamlCommandHelpInfo. This object has properties that you are use to seeing like name and synopsis. PS C:\> get-help get-service | Select…
Have Your Output and Variable Too
There’s a relatively useful suggestion floating around on Twitter on how to save results of PowerShell command to a variable and see the results at the same time. PS C:\> ($data=get-process) I’ll admit this is a clever technique: you get the results from Get-Process written to the pipeline AND a variable $data. The other way,…
On the Road Again
It’s that time of year again: conferences! I’ll be out and about a few places in the next few months and I hope our paths will cross. Here’s a short summary of where I’ll be speaking and when. If you are interested in having me speak for your group or perhaps you are interested in…
PowerShell ISE AddOn ModuleMenu
Recently I did an online presentation on ISE Addons. As I was preparing for the talk one thing led to another, as they usually do when I’m working in PowerShell, and before I knew it I had a new add-on for the PowerShell ISE. This addon creates a menu for all of the modules in…
Create HTML Bar Charts from PowerShell
I saw a very nice mention on Twitter today where someone had taken an idea of mine and created something practical and in production. It is always nice to hear. The inspiring article was something I worked up that showed using the PowerShell console as a graphing tool. Of course someone immediately wanted to know…
Embrace and Extend the PowerShell ISE
I did a presentation today for the PowerShell Virtual Chapter of SQLPass. The recording will be posted later and I’ll update this when I have the link. But in the meantime, as promised, I wanted to make available my slide deck and demos. You’ll need to download the individual ISE Addons from the respective sites….
Valentines Day PowerShell Fun
In case you missed some of the fun on Twitter and Google Plus, here are the PowerShell valentines I sent today. These are intended to be run from the PowerShell console, not the ISE. Also, depending on your console font, you might get slightly different results. I use Lucida Console. #1 write-host (([char]3…
Morning Report Revised
Last month I posted a PowerShell script I called The Morning Report. I received some very nice feedback. One comment was about making it easier to use the script in a pipelined expression. For example, get a list of computers from a text file and create a single HTML report. That sounds reasonable to me…
Friday Fun PowerShell Valentines Day
With Valentine’s Day just around the corner, I thought I should help you out with your gift giving. Remember those bags of candy with the cute sayings like “Be Mine”? Here’s how you can create a “bag” of them using Windows PowerShell; perfect for that extra geeky significant other. Or maybe you’ll just have fun…
Ping a Service with PowerShell
The other day I came across a PowerShell question on StackOverflow about testing if a service was running on a group of machines.This sparked an idea for a tool to “ping” a service, in much the same way we ping a computer to see if it is up and running, or at least reachable. It…