I have had several people comment on my presentation at IndyPASS about the use of what I termed a ‘Library File’. So I decided to give an example of one and explain it usefullness a little.

First off, this file is nothign more than a plain ole powershell file. What it is used for is to store the call to your favorite powershell function files so that you do not have to constantly type the . ./LoadMyFunctionPlease.ps1 calls at the top of your scripts. Below is an example of the contents of my example file…..

#Source all of our coolio libraries

. ./CheckPing.ps1

. ./CheckDrive.ps1

[System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.SqlServer.SMO”)

. ./CheckDBBackupSimple.ps1

Here I just simply place what I deem to be my ‘Cool’ or ‘Coolio’, for the west coast hipsters, function calls and assembly loads. So from the example above, you can clearly see that I am ‘loading’ into my environment my two powershell functions for checkping and checkdrive…as well as the .NET assembly for SMO. Lastly, another CheckDBBackupSimple.ps1 to get the CheckDBBackupSimple function.

Now instead of killing my fingers every time I write a new powershell script. I merely have to use the syntax that I used in my previous post on reading in a file.

. ./SQLScripts_Lib.ps1

A whole lot less typing involved this way. Hopefully, this post will cut down on the amount of carpal tunnel syndrome out there.


Cheers!
AJ