Powershell Error checking

March 8th, 2012 | by | devdog, tips & tricks

Mar
08

Being a programmer by trade, I get thrown into many projects that aren’t always my forte, but I can figure them out and get them working the way that I want.

I’ve been messing with powershell for a while now with VMware, but never really getting into big time scripting with it. Its mainly be something to use to accomplish some various tasks on mutliple hosts. Very little error checking in the scripts since I’m watching them was they run. If I want to put them into a scheduled task or automate them from a web page, more error checking is needed.

Recently, we starting messing around with automation of Exchange 2010 provisioning using Powershell. There are some great cmdlets to accomplish this, but I ran into a particular issue that really bothered me as a programmer and since I spent more than 5 minutes unsuccessfully googling the answer, I figured I’d write this post.

My issue was this, I was attempting to put some wrappers around certain cmdlets to get back whether or not they completed successfully. I hate to be the bearer of bad news, but shit doesn’t always run as you think it would.
I think I found a good way of handling the powershell scripts that do not return a true or false and were causing some false positives.

The issue occurred in the functions such as remove-mailcontact where I would have something along the lines of:

if(remove-mailcontact -identity $ID -Confirm:$false)
{
    "+OK Contact Removed"
}
else
{
    "-ERR Unable to remove contact."
}

This would alway return the -ERR statement.

So now I have expanded upon that and have the following:

Remove-Mailcontact -Identity $ID -Confirm:$false -DomainController $DC -ErrorVariable:err
if($err)
{
    "-ERR Unable to remove contact"
}
else
{
    "+OK Contact Removed"
}

This second method seems to be doing what I want and goes to the appropriate domain controller so I think I’m on the right track…we just need to update the various scripts now. For a little more information on the errorVariable adn other default switches you can pass a cmdlet, check out this blog post from the Microsoft PowerShell Blog.

Comments Closed

Red Flannel Run 2012

February 11th, 2012 | by | in the news

Feb
11

Today marked the official start to the race season for me. I’m not competitive in these things by any means but calling it a race season makes it seem like I know what I’m doing. Signup, run, don’t die. Pretty much in that order. In the end, its all about knocking out one of my goals for 2012.

There were a lot of things different about the Red Flannel Run in 2012 compared to last year. First and foremost, the temps. Last year we were in the mid-30s and I was warm as could be in my gear. This year, I wore pretty much the same thing except the temps were 7 degrees with a -6 windchill. It was cold out there. But with the gear I had on and the running, I warmed up pretty quickly. I just wish I would have had some sort of neck gator on. That would have made a pretty big difference for me. I kept having some breathing issues after the first 1.5 miles and I’m pretty sure it was due to things (mouth, lungs etc) freezing up a bit.

Second big difference, I ran a heck of a lot faster than in 2011. Too fast for the first mile but over all, I shaved off 4+ minutes from the previous year and beat my fastest time from 2011.

The official stats come in as this:
Time: 23:51
Age Group rank: 12
Overall: 70

Not bad for the first time out. I’m hoping for some stronger finishes later in the year when I can get some better training in. Running on the dreadmill is boring and I never want to go more than 2 miles. I’m hoping that once we get over the snow, ice and cold temps I can put some longer runs in and build up the endurance for a faster time.

Comments Closed

Puppet Presentation

January 25th, 2012 | by | sysadmin, tips & tricks

Jan
25

For those looking for the slides from the puppet presentation that I gave last week, here they are.

I’ll be working on getting a screen cast of the demo up in the next week or so. Too many other things distracting me at this moment.

Comments Closed