Home Forums Programming Powershell Using a Helper Library from a powershell script that will be running via a SQl Agent job RE: Using a Helper Library from a powershell script that will be running via a SQl Agent job

  • Replying to my own question. Basically this can be done the following way:

    <#--Get the path where the script is running--#>

    $scriptRoot = Split-Path (Resolve-Path $myInvocation.MyCommand.Path)

    <#--Assuming all the common helper libraries are in the same folder as the main script, do the following--#>

    <#--DatacenterHealthCommonLibrary is just an example library--#>

    $common = join-path $scriptRoot "DatacenterHealthCommonLibrary.ps1";

    <#--Reference it--#>

    .$common;

    There are other ways to do it as well as I found upon investigation. One being convert the library to a script module and then import it using the import-Module. Obviously this would require an additional module installation step before 🙂

    Cheers 😀

    Saptarshi