Sunday, August 7, 2011

Powershell script for bulk adsiedits

Active Directory can be a great place to keep information on your users. Email addresses, departments, full name, phone numbers, and more can be stored in AD and because it's integrated in your user provisioning process (everyone needs a logon) it makes for a logical spot to keep user information. You can even use custom attributes (we use the extensionAttributes for this) to add data that is custom to your organization.

And once you start using this infrastructure to store user data, you will quickly find a need to do bulk changes to this infrastructure (for example when your Accounting Department decides to change their name to the Finance Department, or you get a new CEO and he decides to turn your organizational tree upside down).

ADSIEDIT won't cut it for big bulk updates. Try this script instead.

To run this script you'll need a special .csv file. In the first column you'll want to place the adsi object that you want to match. So, for example, say you have a list of usernames and you wan't to change their email address from user1@domain.net to user1@domain.com. The match address will be their SAM Account Name and the second field will be their new email address. So the text file will look like this:

user1,user1@domain.com
user2,user2@domain.com
user3,user3@domain.com
...

You should NOT include header information in this file. This will get defined when the program is run.

Save the .csv file to a known location and run the script. It will prompt you for the location of the .csv file that you just saved and then ask you for the header information. This is the name of the AD objects that match with your columns. So for our example we would enter:

sAMAccountName,mail

This tells the script to go through AD and find the sAMAccountName for all the objects. If it matches with a value in column1 it then changes the "mail" object to the value in column 2.

That's it. Bulk adsi updates for every value in your .txt!

Let me know what you think and what you see in this script that can be improved.


----adsibulkedit.ps1

# import text file that contains a first column of a property to match on and a the second column is the property to change
# so if you have a .csv file and the first column is the mail and the second column is department you could then bulk change a bunch of users
# based on email address to new departments

$filename = Read-Host "Enter location for the config file"
$fileHeaders = Read-Host "Please enter headers (format is: column1label,column2label)"
$x = $fileHeaders.split(",")
$column1 = $x[0]
$column2 = $x[1]
$configfile = Import-Csv $filename -Header $column1,$column2


$strFilter = "(&(objectCategory=User))"

$objDomain = New-Object System.DirectoryServices.DirectoryEntry

$objSearcher = New-Object System.DirectoryServices.DirectorySearcher
$objSearcher.SearchRoot = $objDomain
$objSearcher.PageSize = 1000
$objSearcher.Filter = $strFilter
$objSearcher.SearchScope = "Subtree"

$colProplist = $column1, $column2

foreach ($i in $colPropList){$objSearcher.PropertiesToLoad.Add($i)}

$colResults = $objSearcher.FindAll()


foreach ($objResult in $colResults)
{
$objItem = $objResult.Properties
# make sure column is lowercase for fair comparison
# This is a hack. Tell me if you know a better way
$column1 = $column1.toLower()
if ( $objItem.$column1 )
{
$attribMatch = $objItem.$column1[0]
foreach ( $row in $configfile )
{
$column1value = $row.$column1
$column2value = $row.$column2
if ( $attribMatch -eq $column1value )
{
$objUser = [ADSI]$objResult.Path
$objUser.put($column2,$column2value)
$objUser.SetInfo()
Write-Host "$column1value set to $column2value"
}
}
}
}


Sunday, October 10, 2010

How Nothing Gets Done

I've got a secret to share. For the last (ugh... few) years I'd come home after a full day's work and think to myself, "Man, nothing got done today."

Now, that wasn't exactly accurate, I am a hard working guy. And actually most everyday lots of things would get done. But these were rarely the things I wanted to get done. Mostly it was fighting fires, responding to the immediate needs of my customers (internal and external), etc. What I realized was that although I did a lot of work it felt like it was rarely any of my project work that, in my mind, was my primary responsibility. And because of that I often left work feeling that I'd accomplished very little. For these important projects anyway, I was falling behind, and failing to get "anything" done.

And I got sick of feeling that way. So a year ago I resolved to myself to figure out how this was happening.

I started by trying to first understand how I worked. I had some ideas of how I worked and of how a typical day went but I decided that working from a template generated these ideas about what happened just wasn’t going to be accurate enough. First of all, I theorized that how I thought the day went and how it actually went were likely two very different things. If you would have asked me how an average day broke down when I started this project I would've said.

40% General Client Support
20% System Maintenance
10% My Projects
20% AdHoc Projects
10% Other

I was curious. Was this the actual breakdown? And how much variance were in these different categories? Which categories stole from which? And, most importantly, how did each of these categories influence my overall output?

It quickly became clear that I needed to start tracking how I spent my day. And, to do it right, I'd really need to be able to do this in easily and in detail. So what to do? Easy. Hit up lifehacker.com by using a google search (site:lifehacker.com time tracking). First hit: top 5 time tracking applications. Top application: Klok.

What a find! I quickly found that Klok did a great job of tracking my daily tasks. I simply created five categories of tasks in Klok (matching the five that I broke down above) and then filled in these categories with the various sub-projects that they had. After that, all I had to do was make a quick update to Klok before I started working on a task and Klok would take care of the rest.

And so I Kloked. I Kloked in detail. (No, I did not have a category for bathroom breaks.) And in the end it turns out that I probably Kloked in too much detail, but for the purposes of this project that was okay.

And I did this for almost ten months.

And what did I find? How accurate was my breakdown? In short, not very.

Interestingly, of my five categories they essentially all broke down to the same amount of time.

18.0% General Client Support
20.0% System Maintenance
21.6% My Projects
20.7% AdHoc Projects
19.7% Other

And what about the category that I was most concerned about (My Projects)? Interestingly, this was the category I spent the most time on and I never would have guessed that before tracking with Klok.

However the data did provide great insight into why “nothing” ever seemed to get done with these projects. And to understand what happens we need to take a closer look at these five categories and how they relate to each other.

My workplace is very focused on high levels of customer satisfaction and responsiveness, because of this I know that the expectations of my managers are that when I receive a call from someone that needs help I need to answer that call and help that person get a resolution. This is, and always will be, a priority. This means that time cannot be taken from the 18% General Client Support. There may be weeks that this is higher, and there may be weeks where this is lower but for all practical purposes I can write off 18% of my time every week to helping with problems that come up.

20% System Maintenance? That category is also a priority. There are daily administration tasks that must be done as a matter of basic operations. System maintenance needs to be performed to keep things running. Right off another 20% of every week to these tasks.

The 19.7% Other category? Kind of the catchall category that includes things like HR related meetings or work tasks. General meetings and other kinds of miscellany that are also mostly unavoidable and, therefore, result in another 19.7% loss.

So what’s that leave for project work?

42.3% of a work week.

And that gets split up among the remaining two categories. My Projects and AdHoc Projects. What are these? My projects consist of projects that I’ve identified as most essential to my core job responsibilities. There were eight of these projects that I worked on over the course of these ten months.

What are AdHoc Projects? These are projects that are of primary importance to others. I get involved because I have a specific level of technical expertise that is often beneficial, or even (sometimes) necessary, for the completion of their projects. And although these projects are also something I’m responsible for they often fit in the “all other duties as assigned” job description catchall. I had 31 AdHoc projects over the course of the ten tracked months.

Maybe you can see where I’m going here. I hypothesized that with the two task categories that I could actually manage the workload (the other 57.7% is already accounted for and outside of my control) there would be one task that I would steal time from to feed the other. And I hypothesized that this would be the AdHoc projects. And, when you think about it, that’s really the only way it could be. Considering that the other three categories are an accepted part of what has to be done every week, in order to get work done in one of these categories I would have to take from the other. And the data showed just that.

Month-to-Month time breakdown




Week-to-week time breakdown


Just by looking at these graphs you can see that the data is validating some of the hypothesis. With the week-to-week graph you can see that there were times when My Project Work would completely go away and others when AdHoc Project Work would disappear. That was rarely the case with the other categories. And you can see that these other three categories stayed relatively constant which also validates the hypothesis.

Further data analysis also validates this. Although the mean amount of time that was spent on these tasks was essentially the same (this is reflected in the breakdown where they were all near 20%) the standard of deviation was very different. The standard of deviation (per week) for the three non-project related categories were 2:46, 3:02, and 2:45. Adhoc Project work had a weekly standard of deviation of 5:09 and My Project works standard of deviation was 5:46! This showed definitively that my hypothesis was right, time was mostly stolen from My Projects to feed the AdHoc projects.

So was this how nothing got done? Well, yes. I could clearly tell that this was why I had a difficult time with getting “something” (my projects) done. The Klok data also gave insight to how I could be more efficient in organizing how I spent my day and the inefficiencies of doing multiple projects concurrently versus serially, etc. Oh yeah… and I also had to figure out what to do about AdHoc Projects stealing from My Projects! But that’s for next time…

Tuesday, August 24, 2010

Double check your A's and B's

So a little while back I tweeted a blog post on A/B testing a product logo. Now I love A/B testing, the thought that you can do a simple test online and actually measure the impact of minor changes in web copy hit all (well... actually some of the many) of the buttons that get me excited; human behavior, statistics, measurement, and the TRUTH!

So when I came across this blog entry that talked about how a 99 designs logo was handily trumped by a one-off custom logo it was a perfect tweet. A perfect example of what A/B testing can show. That a cheap custom logo was more effective than a 'generic' logo by 99 designs.

But this tweet would teach me two things.

1) That if you're formulating an opinion about something and you have access to an expert in that something; ask them about it.

2) Do this BEFORE you publically weigh in with your opinion.

So after tweeting this I sent the link directly to a friend who does web design for a living and she immediately responded back with a couple very valid criticisms of the original this article.

These were; the power of the first logo was that it had a bingo card which would validate to the person that clicked on the ad that they were in the right spot and that the rest of the site was clearly designed to support that original logo. In doing the A/B testing the tester had taken his original site and simply replaced the original logo with the 99 designs 'generic'!

Once that was pointed out to me it seemed clear that the A/B testing was flawed. Because, after all, the A/B test was really the web page not simply the logo. And once this was pointed out to me it seemed clear that the B page was fatally flawed by its discontinuity.

Thank you expert.

Monday, August 2, 2010

Does Google get social networking

A work friend (@powdernine) sent me a link to this presentation by a Google employee on social networking (http://www.slideshare.net/mobile/padday/the-real-life-social-network-v2).

As I read it, it posits that online social networking has many barriers that need to be removed before it will be fully adopted by users (privacy concerns, the dangers of broadcasting a message to unintended recipients, etc.) But what struck me again and again in this article was that he seemed to as point out all the ways that online social networking was different that offline. And that the challenges would be to create a system of online social networking that was more consistent with meatspace.

I don't think this necessarily so. I think that online social networking is different than what we've done before. It's not a new type of communication but it is a incredibly significant shift in how we present ourselves to others.

Is it about your friends? Or how YOU look to your friends? (Of course it's some of both)

These questions are what people are interested in and I'm not sure it needs to be like it has in the past. Sure we've got the same brains, the same traditions, the same needs. But we're operating inside of a different system. How much power is in the system? Will our past shape our wants and needs of the new system? Or can the system shape our behavior?

One thing is for sure, I would've put more stock in this presentation if it was done by someone from Facebook.

Tuesday, July 27, 2010

I loves me some Gmail

I'll give you one reason why gmail is the best email application in the world; it makes it soooo freaking easy for me to address emails to my recipients. I didn't need to build an address book, I don't need to query Active Directory, I've actually done NOTHING to help make my experience easier. But when I start to type a name into my gmail to: field within about 3-4 keystrokes it's going to autofill with the correct email address with what seems like 95% accuracy!

I didn't have that feature before gmail. (And often still don't). And it's a killer feature. And probably one of the reasons why google thought they should build a new email app even though email is one of the oldest Internet applications there is.