The thoughts of a SysAdmin

Archive for March, 2011

The End of A Long Commute

without comments

I am nearing the end of my long daily commute from Philadelphia to New York City. The end result hasn’t been too bad, although over the past six months the daily hour and a half commute has worn on me at times. My journey started when I took my current position at Stack Exchange as a Systems Administrator in their New York offices.

My first inclination was to move up there ASAP which, looking back would probably have been the better idea even if I was losing sleep over the stress finding a place in NYC in about a week was causing me. The journey for me began when I accepted the position, I gave my notice at $evil_corporation excited to start in on an adventure at a hot VC funded startup. Of course I started looking for a place, hit up my sister for advice (since she has lived in NYC since she went away to college). I thought I had everything set, spent the week lining up apartments to look at during the week between knowledge dump session. I then intrepidly headed up to NYC for the weekend to look at these places. I had 13 apartments lined up to look at over the course of a weekend.

I figured I would surely find a place that would work during that time. The first rude awakening that told me the NYC real estate market was nothing like what I was used to was when I woke up Saturday morning to find that 8 of the places where no longer available. Wow.

The second realization was that Manhattan apartments where … small, very very small. Although, oddly I was OK with this. I figured if I was going to move to NYC I wanted to be in the center of it all – at least for a year or two – while I’m still young enough to appreciate it. So, feeling a little bit depressed at not having found a place, and stressed out that I only had one week between my last day at my old job, and my first day at my new job I sat down and decided that it would be best to commute for a little while. I was thinking that this would only last a few months at first but that has transformed into six months at this point!

I have survived the commute now with the help of a few gadgets – and being a geek would you expect anything less?

* Laptop with cellular modem
* iPod
* Noise Supressing headphones
* Kindle

Being able to listen to music, read, serf the internet – and occationall do some work on the train was a great help in me keeping my sanity during these long commutes to and from New York.

Now that I have gotten a place in NYC, and will be moving up in the next few weeks I’ll miss my life in Philly but i’m looking forward to starting anew in NYC.

Written by George Beech

March 31st, 2011 at 6:08 am

Posted in Life

Full Featured Email using powershell

with 4 comments

Note: This is copied (thank you wayback machine) from a previous incarnation of my blog. I was very sad when I realized this post was gone, then very happy when wayback machine had it

A little while ago i spent a lot of time trying to figure out how to send an email that fulfilled the following requirements:
Multiple Recipients
Attached File
Meaningful Subject
Sent without an external executable
Thanks to powershell’s ability to access .Net libraries, this is a fairly simple, however not quite so well explained – at least that i could find – process.
Let us start simply, with the basic SMTPClient Object, and setting the Server Variables, settings, etc. The most basic way to configure your server is to simple create a.Net System.Net.Mail.smtpClient object, and set the email server hostname, taking the defaults.

$SMTPClient = new-object System.Net.Mail.smtpClient
$ = ""

Simple, right? Then lets get a little bit more complicated. Lets send an email to a host that requires authentication. To do this, we are going to need another .Net object: The NetworkCredential Object from there we can set the domain, user, and password, set these values on our SMTPClient.

$Credentials = new-object System.Net.networkCredential
$Credentials.domain = ""
$Credentials.UserName = ""
$Credentials.Password = ""
$SMTPClient.Credentials = $Credentials

The above code is fairly self explainitory, if you were to display $SMTPClient (Just type $SMTPClient on the console) before and after when you set the Credentials property you can see that is has been set. There are a few other options that you can set on the SMTPClient object, including Port, and SSL to see all that you can do issue

$SMTPClient | gm

Now, we have the Client setup, we want to configure message that we want to send. This will include setting up the Subject, To, From, and Body. What I do to send mail is use an overload of the SMTPClient object that lets us use System.Net.Mail.MailMessage to send the mail, it gives you ALOT more control over your message. First lets get ourselves another .Net Object, the MailMessage Object.

$MailMessage = new-object System.Net.Mail.MailMessage

The next thing I want to do is Setup my addresses The To: and From: addresses are yet another .Net object System.Net.Mail.MailAddress. Here is how you set those up, it is very simple and all you really need is the constructor which is overloaded. You can setup your address in the following two ways.

$Address = new-object System.Net.Mail.MailAddress("[email protected]")
$Address = new-object System.Net.Mail.MailAddress("[email protected]", "Display Name")

Either was you want, you need to create at least two one for your sender, one for your recipient. After we get those options out of the way, we just need to do the final setup on our message. That will include setting up the Subject, Body, and feeding it the To: and From: Addresses we already created.

$MailMessage.Subject = "Hello World!"
$MailMessage.Body = "String Body"
$MailMessage.Sender = $Sender
$MailMessage.From = $Sender

Why, you ask, am I setting the $Senter twice, the Sender property is the Displayed From Address, while the From property is the repy-to address. You can send an email with an html body just put the code in your Body string, all you have to do is specify the boolean IsHtmlBody property.

$MailMessage.IsHtmlBody = $true

Now, how about adding an attachment. This is done very simply with another MailMessage property set to the .Net Attachements object

$Attachment = new-object System.Net.Mail.Attachment("")

That is all there is to that. There is one last thing we have to do to get this mail off and on it’s way. Simply. Send It!


Written by George Beech

March 25th, 2011 at 12:22 pm

Posted in Powershell