I am having a Powershell Script, A.ps1
that calls some functions from a Helper script HelperFunctions.ps1
. In order to execute A.ps1 from console I make sure I have the helper script imported. I use the following code.
But my actual requirement is that the script A.ps1 be executed from a SQL Agent job. I execute it as an Operating system step:
C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe -NoProfile -WindowStyle Hidden -Command C:\Users\querty\Desktop\Scripts\A.ps1
When I run the script via SQL Agent job, then referencing the helper library as .".\HelperFunctions.ps1" throws an error and I need to use the full path of the helper function(even if the main script and the helper are in the same location).
Now, my problem is this SQL Agent job will be running in multiple production servers. I do not know where the actual scripts will be placed and so I cannot hardcode and mention it inside the main script.
I want a way to reference the helper script in the main script without mentioning the full path as this might change from server to server.
One way of doing it is by passing it as a parameter but I want to keep it as a last option. Any other way I can reference the helper script directly from the main without caring about the actual path?
Thanks and Regards