Date: October 26, 2010
Note: You might find the first part of this article too technical and most of the terminologies are from IT perspective. If you're a non-IT, you may focus on the second part of this article which contains the actual message that I wanted to convey with you. These are the lessons that I've learned based on what I've experienced the past few days in my work.
Last week, I have written an article about my latest automation in my current job. It was entitled Powershell : My new language.
For those who are not able to read the aforementioned article, basically, I have created a script that will check if all users who have access to our supported applications still exist in Active Directory or in other words if they are still part of the firm. I named my script as Leavers Checker. It is written in PowerShell programming language which is new to me because I don't really have previous exposure on writing a PowerShell script. I am more exposed in Unix scripting.
Everything is already working. The script is running fine from my local machine. Basically, the script that I have created will save us a lot of time and effort.
The problem started when I decided to deploy it in one of our production server. It was not able to execute the script because of missing module (SQLPS) in our production servers which is needed to be able to access our production database remotely.
I then seek some help from our infrastructure team to install the necessary program/s or PowerShell module to make my script work.
But then looks like my request is also new to our Windows support team.
They tried to install few programs already but unfortunately, I am still getting the same error. The system is still not able to recognize the command that I am using to extract the list of users from our database remotely. I felt hopeless already because even the Windows expert couldn't resolve my issue and couldn't make my script run.
But then I did not loose hope. I really wanted to make my script work because it will be very beneficial for the team in the long run.
Yesterday, I tried to google the alternative command I can use which will not require additional program to be installed into a server. And luckily, I bumped into a blog that has very the same issue as mine and when I scrolled down further, I found the answer!.
Initially, I've been using invoke-sqlcmd to access our database remotely and get the list of users directly from the DB. I found the useful post that has all the details in it.
Below is the portion from the post which I found to be very useful.
function SqlQuery($server, $database, $query)
{
$connection = New-Object System.Data.SqlClient.SqlConnection
$connection.ConnectionString = "Server=$server;Database=$database;Integrated Security=True;"
$connection.Open()
$command = $connection.CreateCommand()
$command.CommandText = $query
$result = $command.ExecuteReader()
$table = new-object “System.Data.DataTable”
$table.Load($result)
$connection.Close()
return $table
}
SqlQuery $Server $Database "SELECT * FROM Staff"
This line actually caught my attention:
And since I know that our production server has .NET installed, I know that this solution might work. But then again, there's also possibility that it won't work.
So I modified my code and use the aforementioned script to extract user details from our database and run it to my local machine first. It works!.
And here is the thrilling part again. I deployed my script to one of our production servers and I almost jump with joy when finally, it works!. My script is working perfectly!.
And this is one goal down for this fiscal year!.
What I am trying to say is, there seems to be a situation where you already felt hopeless. That despite your multiple attempts to solve a problem, you just keep on failing. Despite on how many times you stand up and try, you keep on falling.
That whenever you tried to apply the available solutions, it's not working at all. You've already seek other's help but it seems that the situation is not going along with you but it is always against you.
Instead of pushing through with your current strategy, where despite of your multiple attempts, none of them actually worked, why not try a different way? Try another path! Turn right or left and check if that path will lead you to your goal.
Just like in mathematics right? There are multiple ways we can solve a specific problem but what matters most is we have arrived to the correct answer. Regardless of the formula that we used or applied, as long as we have achieved the expected output, then we should be good!.
When there's a will, there's a way. Charaught. Pero totoo sis, we just need to explore and find new ways to solve the problems. I know that every problems has a solution anyways.