Quantcast
Channel: SQLServerCentral » Programming » Powershell » Latest topics
Viewing all articles
Browse latest Browse all 467

Using a Helper Library from a powershell script that will be running via a SQl Agent job

$
0
0
Hi I am having a Powershell Script, [b]A.ps1[/b] that calls some functions from a Helper script [b]HelperFunctions.ps1[/b]. In order to execute A.ps1 from console I make sure I have the helper script imported. I use the following code.[code="plain"].".\HelperFunctions.ps1"[/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:[code="plain"]C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe -NoProfile -WindowStyle Hidden -Command C:\Users\querty\Desktop\Scripts\A.ps1[/code]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 RegardsSaptarshi Chaudhuri

Viewing all articles
Browse latest Browse all 467

Trending Articles