Mistakes were made………again
Hello again! In case you haven’t already figured it out, I really took a rather foolish approach to blogging, the correct motives and objectives are there but the execution was shit. Because of this, I’ve made some changes to ensure that I’m taking a professional approach to my blog. The keyword here is professional. One thing that I’ve constantly been struggling with has been distancing my job related work from my blog topics and content. The whole point of this blog is not for discussing the projects I’m working on at work but rather the concepts that I’m learning while doing so. As a result, I’ve basically been writing a variation of a given script or function that I was working on all from memory. The reason for this is because the only way that I can test my newly learned concepts is at work. I think now is as good of a time as any to change that.
Construction in progress
To mitigate this problem, the solution was obvious. I needed to build myself a test environment that can be used for testing my scripts and really just to learn more about it in general. Being that I don’t actually possess any server hardware, an old laptop will have to do (for now at least). I grabbed a couple evaluation versions of Windows Server 2012R2 and SQL Server 2012 and spun up my first ever testing environment. The environment is comprised of a host machine running Windows Server 2012R2 along with another instance of Server 2012R2 running in Hyper-V with SQL Server 2012 components installed. With all of that in mind, I say we break this b**** in!
Something, something SQL querying for the third time
And what better way is there to break my environment in other than reattempting the post that brought all of this about. Additionally, I’m also going to utilize the Invoke-SQLCmd function rather than my previous method of constructing the whole query and connection object manually. A fellow redditor (/u/RhysA from /r/SysAdmin) advised that my method for constructing the query, connection, etc was far more complicated than using the other approach. WOW, he could not have been more correct. Not only was it 100% easier using Invoke-SQLcmd for this objective, it also took half as many lines of code. So let’s go ahead and dive in to my new script Get-EmployeeData.
Pretty easy peasy right? I’m still a little shocked and even a little embarrassed that I didn’t realize this part earlier. In fact, I’ve also started implementing this method at work. Initially, the only reason I used the previous method is because it was already part of our module and I assumed that this must be the best way to do it. Clearly, I should have known better :). So now for the drum roll, here’s the results of my first run in my own test environment.
For my first test, I wanted to make sure that the script would validate whether the value for F_N was the same in both tables, to which it returns “values match”.
After confirming that my script was, at the very least, working. I altered one of the values for F_N in one of the tables and ran the script again.
Well how about that? 🙂
I’ve posted the script on pastebin for anyone who is interested and the link is listed below. Please let me know if you have any questions, comments, etc. and thank you to any and all readers.
Get-EmployeeData
Two quick side notes
A big “thank you” goes out to my buddy RV for helping me put this environment together. There was no shortage of problems trying to get this all up and running on an old Dell E6420. Lucky for me, I happen to know a Jedi master with this type of stuff and after a few days, most of the bugs were worked out.
Additionally, I also wanted to give a shout out to the /r/PowerShell and /r/SysAdmin communities. In addition to be incredibly helpful and informative, being on the receiving end of so much positive feedback really goes to show how great the folks are that make up these communities. As I said in the beginning, my whole purpose for doing this is so that I can learn and develop my abilities. After only a handful of posts, I already almost can’t even quantify how much this has helped. Even better, now I have a function home test environment. That being said, thanks again everyone!