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

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

Goal Tracking

January 3rd, 2012 | by | in the news, tips & tricks

Jan
03

On the 1st of the year, I put our my usual public goals for 2012. I have some typical goals in there of some fitness goals, career type goals and general health goals. Some of these are pretty cut and dry to track progress. I want to run 5 5K races, pretty straight forward.

But how do you track something like getting more sleep?

Here is where Mercury App comes in. I’ve been using this product for over a year now and have mainly been tracking things like my weight and job satisfaction. Adding to it Sleep time, not only how I feel about the sleep I got but actually tracking the number of hours should give me a good overall graph at the end of the year of how well I did in getting that 7+ average that I’m looking for.

So if you have a goal that you are working on the for the new year, start tracking your progress. You’ll be amazed at what you can accomplish when you put your mind to it. Because the only one stopping you is YOU!

Comments Closed

Pizza and Puppet

December 15th, 2011 | by | in the news, sysadmin, tips & tricks

Dec
15

For those looking to see my handsome mug in person and listen to my beautiful tenor voice, I will be giving a Puppet demonstration at the January 2012 CIALUG meeting. Details on the event can be found on the events page of the cialug.org site.

Puppetlabs has stepped up to offer sponsorship of the event so besides my insightful talk, there will be pizza and t-shirts that will be handed out while supplies last or whatever game we come up with to give them away. I have a whole box of them so hopefully many of you are sporting the latest in puppet wear before the night is through.

So put it in your calendar now to join me for Pizza and Puppet on January 18th at 7PM in the LightEdge corporate headquarters.

Comments Closed