PowerShell Error Output

I’ve implemented some crazy ways of error handling over the years.  I wanted to quickly show and explain what I currently put in my Catch block for most of my PowerShell functions.  Here is a typical catch statement in one of my functions: Write-Warning “Unexpected error occurred while executing $((Get-PSCallStack)[0].Command) with exception: $($_.Exception.Message)” Write-Warning “Command:…

0

PowerShell Prompts – Part 2

In Part 1 of this series, I talked about an Approve-Action function.  This is great for a single go/no-go approval.  Unfortunately not all decisions are so boolean.  For more advanced problems, I developed the Confirm-UserInput function, which instead focuses on validation input versus action approval.  The purpose of this function is to enforce user input…

1

PowerShell Prompts – Part 1

I always get nervous when I am writing scripts that could negatively impact users consuming a service, such as rebooting a server or restarting critical services.  I do my best to make sure the person running the script is aware of what is about to happen.  I feel the best when I can make sure…

4

Log-Event

Recently I had a need to write to the event logs using PowerShell.  I knew there was a built in command for this action so I decided to test it out.  After some time using the Write-EventLog cmdlet, I kept getting errors generated which seemed to be symptoms from the following constraints of the event…

0

Shutting Down an Exchange Site

The argument could be made that this script is not something that has a practical use.  One of my customers had a requirement to quickly (and gracefully) shut down an entire site of Exchange servers.  I assume the scenario would be due to some kind of natural disaster or cooling issue in a datacenter.  I…

1

Caching Objects in PowerShell – Part 2

In my previous post about this subject, I demonstrated how to cache objects using an XML file. Let’s take a look at how to load, manipulate and save the data again. Since the Export-Clixml cmdlet retains the data type in the XML file, we can perform actions on the objects in memory that are type-specific…

0

Caching Objects in PowerShell – Part 1

In the first section of this two part series, I will discuss caching objects to disk in PowerShell, and reading the cache back into memory.  I recently came up with this solution at a customer site where I was running a script as a scheduled task and needed some data to persist after the task…

0

PowerShell Performance: Write-Host

  This month’s post will be a short one – and there’s not much code to this topic, it’s just an observation.  When I write scripts, I like the idea of adding some output to track what my script is doing, especially if there’s an issue with the script.  It’s so much easier to find…

1

Estimating/Calculating Execution Time

Over the years, I’ve noticed that I develop a general routine depending on the needs of my current customer.  When I get to work in the morning I generally check a few items that I know can develop into hot button issues.  As a general rule, if I am going to repeat a task more…

0

Collecting Mailbox Counts per Database Using LDAP

Recently I have been gathering a lot of mailbox data for a customer running Exchange 2010 that is in the process of upgrading from Exchange 2007.  One of the more frequent requests has been for mailbox numbers, often broken out by database.  It’s key to know the current state of your environment, especially during an…

4