facebook twitter flickr rss

The Power in Powershell: Creating AD Users From a SQL Database - June 5th, 2012

Part of my current job has become building automation processes for online student services. One of our goals was to get our Active Directory services populated with student data from our student information system, which uses a Microsoft SQL database. After talking with contacts from other schools that use the same system, I was introduced to Powershell.

At a recent conference I attended a presenter referred to Powershell as “Microsoft’s version of Linux bash scripting”. I would wholeheartedly agree with this description. It takes the power of .Net and brings it to the Windows command prompt.

Another nice thing about Powershell is that people have already developed Powershell scripts to interact with AD and SQL that are free to use. The script I am going to demonstrate uses Idera’s Powershell Scripts to do some of the heavy lifting.

I’ve searched the net for examples of scripts that already do this, but didn’t find anything complete enough for my particular situation, so I thought I would include my own solution.

Here is a breakdown of the script:

."C:\path to script\New-IADUser.ps1"

This is an include statement pointing to Idera’s New-IADUser script. This will allow you to later on call the function that creates a user in Active Directory.

$connString = "data source=database location;Initial catalog=database name;uid=user name;pwd=password;"
$QueryText = "SELECT * FROM user table name WHERE this='that'"

Then I’ve defined the strings for connecting to the database. The first string defines the database to connect to and the login information. The second Querytext string contains your query for selecting the desired user information from the database.

$SqlConnection = new-object System.Data.SqlClient.SqlConnection
$SqlConnection.ConnectionString = $connString
$SqlCommand = $SqlConnection.CreateCommand()
$SqlCommand.CommandText = $QueryText

This section creates a connection to the database and queries using the strings defined from the last example.

$DataAdapter = new-object System.Data.SqlClient.SqlDataAdapter $SqlCommand
$dataset = new-object System.Data.Dataset
$data = $dataset.Tables[0]

Then we create a data table object and fill it with information returned from the database. Lastly, I assigned the table data information to a value.

foreach ($data_item in $data.Rows) {
  $name = $data_item[2] + " " + $data_item[3]
  $response = [ADSI]::Exists("LDAP://CN=" + $name + ",OU=user organizational unit,DC=mydomain,DC=com")
  if($response -ne "false") {
    New-IADUser -Name $name -sAMAccountname $data_item[0] -ParentContainer 'OU=user organizational unit,DC=mydomain,DC=com' -Password $data_item[1] -Mail $data_item[4] -EnableAccount -UserMustChangePassword

This foreach statement loops through the various rows in the table object that we created. The $data_item values returned are assuming that the table rows look like this: id number | password | first name | last name | email. The values may vary depending on how you query your database. The third line uses ADSI to check if the user with the name in the row is the same. The next line is a conditional statement that will run the New-IADUser function if the user is not already in Active Directory.

Posted in Thoughts | No Comments »

Redwoods and Hard Drives - July 22nd, 2010

Redwood National Forest - Big Tree
So, a few weeks ago I got a chance to visit Northern California and Southern Oregon.  Some of the most beautiful country I’ve seen.  In my week-and-a-half of hiking, mineral baths, good beer, grass-fed beef, and other great endeavors I got a chance to visit the Redwood National Park and the state parks along the Northern Pacific Coast of California where the great trees reside.  A redwood tree can live to be 2,000 years old, if permitted to do so.  Redwoods are almost impervious to fire, because of their mass, so a whole forest would never go up in flames as easily as the other pine and fir-covered lands that make up Northern California.  These groves had to have been thousands of years old.

The famous library of Alexandria, Egypt was a great collection of knowledge.  The ancients gathered thought throughout the lands of Alexander’s conquests and eventually it became the first research institute.  Theories, ideas, and concepts were tested and developed.  One of these thinkers, Aristarchus of Samos had a curious idea that the Earth traveled around the Sun as documented by Archimedes.  Of course we do not have access to Aristarchus’ original scrolls.  Several times the library was consumed in flames and much of the knowledge generated by the greatest thinkers of the ancient world was lost.  It wasn’t until about a thousand or more years later that Copernicus came to this same conclusion; the redwoods kept growing.

Lately I’ve been daydreaming about the trees or contemplating something Carl Sagan said on a Cosmos episode and every once in a while I think about where we are today.  I think about hard drives and the fact that the Library of Congress is archiving our Twitter feeds.  Not to say that all the best and brightest use Twitter, but it is an example of where we are today.  It is a snapshot of our collective history.   The World Wide Web, in which Twitter inhabits, is too.  That and a repository of knowledge.  The trees are touching the sky.

I see a lot of push away from the static (and flammable) printed page to the dynamic world of the digital media.  Information is readily available but easily changes with the click of a mouse button.  Take Wikipedia for example as a constantly-evolving database of information. But alas, the internet is a large array of interconnected computers and all this knowledge, all this history, is stored on devices that require a flow of electrical current to perform.  The redwoods require water and sunlight.

Say that the human population was wiped out by disease, war, disaster and famine (you know, the typical stuff) and some alien race happened upon our planet.  A curious race that is in to planetary archeology.  Go along with me here.  How readily available would our hard drives be to these visitors?  Would they have the technology to decode our zeros and ones.  They would probably still see the trees (unless we removed them all).

Hammurabi’s code was written in stone that we have unearthed.  In the distant future will our digital world be as easily extracted?  Will our systems sustain our own disasters?  I think in many ways that our ideas are as fragile as those that sat in the library of Alexandria.  Our knowledge is fleeting, as are we; only nature perpetuates.

Posted in Thoughts | 2 Comments »

Why the iPad Doesn’t Support Flash – Personal Speculation - February 21st, 2010

Webkit Logo

Recently, I went to an Apple training session, which may have been more of a sales pitch, but it was good and informative and we picked up some tools from it.  One of the questions that one of my colleagues brought up was whether Apple was going to support Flash on its mobile device browsers.  The salespeople alluded somewhat to HTML5.

I’ve been watching the recent emergence of Webkit as a popular browser engine. It’s the backbone for Safari and many browsers for mobile devices, touting major support for HTML5 and CSS3.  I’ve also recently read an article where Wired magazine had formed a partnership with Adobe to develop their magazine app for the iPad.  Surprisingly it uses Flash, but within the Adobe AIR platform.  AIR is platform agnostic and provides a way in which your Flash/Flex/AJAX web application can be run as a desktop/mobile application.  This, to me, seems like an interesting move for Adobe.

CSS3, on the other hand is looking to be a contender with Flash animation (jQuery too).  The Art of Web posted a great article on how to use CSS3′s 2d transformations properties.  Make sure you are viewing it in Safari or other Webkit browsers for best results.

As a CSS fan, this looks very promising.  No Flash, no jQuery knowledge; None of that is required.  You just need an understanding of CSS.  As Apple, this probably looks like an opportunity to make their browser (Webkit) the standard, especially on mobile devices right now.  Also maybe another opportunity to rid itself of Flash as a browser application.  The only drawback to HTML5 CSS3 is the same drawback that affects all new adoptions of HTML, XHTML and CSS.  It takes some time for all browsers to adopt these standards and takes time for developers to use such standards; some don’t fully adopt them anyway (thank you, Microsoft).

Apple is leading the race nonetheless and I think HTML5 and CSS3 should be taken seriously.  I don’t think Adobe should be ruled out though when it comes to engaging, interactive media.

Posted in Thoughts | No Comments »

Phone Validation Using Really Simple Validation Plugin - January 15th, 2010

From past posts you could probably ascertain that I’ve taken quite a liking to jQuery.  Lately I’ve been developing a form for my brother, Karl’s drafting service and have used this handy javascript framework.  There is a jQuery plugin that I’ve been working with called Really Simple Validation that presents a simple, easy-to-use way of validating your forms before submitting them.  It also allows an individual to implement their custom functions for validating your forms.

Karl’s order form required a specific phone number format (xxx-xxx-xxxx).  Unfortunately, Really Simple Validation does not have pre-made phone number validation.  I scoured the internet for such a function to no avail, so I decided to write my own custom function for RSV.  It’s fairly simple and straightforward.  Here is the javascript code:

function phoneValid()
var phoneRE = /^\d\d\d\-\d\d\d-\d\d\d\d$/;
var val = document.getElementById(“phone”).value;

if (!val.match(phoneRE)) {
var field = document.getElementById(“phone”);
return [[field, "Please enter a valid phone number format (xxx-xxx-xxxx)."]];
return true;

The first variable created (phoneRE) is a regular expression and is used to match the sequence of phone number (xxx-xxx-xxxx).  The second variable (val) is the value of the particular form input field that has the id of “phone”.  Below that is a conditional statement that returns an error message if the value of the input field doesn’t match the particular regular expression defined as phoneRE.  If you look within that statement you’ll see “return [[field, "Please enter a valid phone number format (xxx-xxx-xxxx )."]];”.  This area is required for RSV and will display the message if an error is thrown.  The field variable points to the form input field with the id “phone”.

Now that the function is created you just need RSV to make a call.

onCompleteHandler: myOnComplete,
rules: [

To make this coexist within your form you will have to change “#order_form” to the particular id that you have given to your form.  If you look at the line: “function, phoneValid”, you’ll see where the function we created above is being be called.

That’s it!  For those new to jQuery remember that you need to include the jQuery script and the RSV plugin script as described in the links above.

Posted in Thoughts | No Comments »

The Science of Miracles - October 11th, 2009


“Thermo-dynamic miracles… events with odds against so astronomical they’re effectively impossible, like oxygen spontaneously becoming gold. I long to observe such a thing.  And yet, in each human coupling, a thousand million sperm vie for a single egg. Multiply those odds by countless generations, against the odds of your ancestors being alive; meeting; siring this precise son; that exact daughter… Until your mother loves a man she has every reason to hate, and of that union, of the thousand million children competing for fertilization, it was you, only you, that emerged. To distill so specific a form from that chaos of improbability, like turning air to gold… that is the crowning unlikelihood. The thermo-dynamic miracle.”Dr. Manhattan, “Watchman”

I just saw an excellent documentary about the city-state of Athens titled: The Greeks: Crucible of Civilization.  It covers the invention of democracy and the people that helped pave the way towards this road.  What I find incredible is that the idea of democracy was not created in the Fertile Crescent or the Nile River Valley where thought had a good chance to flourish, but in a terrain as rugged and unyielding as Greece.  What’s even more interesting is how it came about.

Athens was ruled by an aristocratic class of Greeks that was constantly vying for power.  With the help of Spartan forces, Isagoras gained power and attempted to keep it by banishing those that were a threat to his rule.  Then, by a strange turn of events, the Athenian commoners rise up and successfully retake their city.  The exiles that Isagoras had banished were asked to return and help restore rule back to Athens.  The aristocrat Cleisthenes, who had been deposed by Isagoras, modified the system of government so that decisions were made by districts of Athens rather than the original aristocratic families.  He helped create a government for the people.

The small city-state of Athens goes on to defeat Xerxes and the mighty Persian Empire, fighting for their freedom.  Eventually they become a strong naval power, a place of trade and a harbor for ideas.  Little do these ancient people know how far into the future that their ideas have persevered.

This gets me to thinking how fragile our timeline can be in the shaping of our lives.  If the people of Athens had never risen up or were defeated by Isagoras the idea of democracy may not have even entered our mindset.  How miraculous it is that we live in the society that we do and how lucky (or blessed) we are by the events of the past that have brought about this present.

There is a story in my family about my great-grandmother missing the Titanic and coming over on the Carpathia.  I have seen documentation of her being aboard the Carpathia, but nothing to prove she had a ticket to board the Titanic.  Supposedly, she was in an arranged marriage to a Polish man in the United States that had paid for her trip.  After missing the boat in one of the world’s most tragic events, she arrived to find her fiancee “too old”.   She ended up marrying a Ukrainian miner with the last name, Holodnick (Golodnyuk).

As Dr. Manhattan said, “…a thousand million sperm vie for a single egg. Multiply those odds by countless generations, against the odds of your ancestors being alive; meeting; siring this precise son; that exact daughter…” It’s incredible that you or I even exist right now to experience each other’s company and this world that we inhabit.  One slight change in the timeline, such as your mother falling in love with another man could mean someone else existing.  What if your mother never existed in the first place?

Scientists are working on it, but have yet to discover the exact conditions in which human life was created.  Although the universe is large, what is the probability that complex life forms exactly like ourselves would come to being over millions of years?   What is the probability they would be living in a free society?  What is the probability that they would have the same personalities or that they would even perceive such things the same?  The fact that we exist on this planet is a miracle in itself.

Some days I find myself seeing everything as tasteless and mundane.  I get impatient when things don’t work out the way I wish they would.  I forget how much of a blessing it is that I’m even here.  We should cherish the moments that we have on earth and be thankful that we’re taking part in this experience we call life.  We should be grateful for the country that we live and the freedoms that we have.  One shift in the timeline and we might never have had such a great opportunity and there’s always a chance we could lose it.

Posted in Thoughts | 1 Comment »