Product: PowerShell Studio 2021 (64 Bit)
Build: v5.8.183
OS: Windows Server 2019 Datacenter (64 Bit)
Build: v10.0.17763.0
I have what I am hoping will be an easy/quick answer for someone. I do not want to keep recreating or copying my functions from the Globals to a job tracker so that I can utilize it. I read in another post in this forum that you can dot source the globals. Admittedly, that post was from like 2015.
I tried it anyway and it does not seem to want to work.
I am placing ". .\Globals.ps1" in the Jobscript of my jobtracker. I have also tried ".\Globals.ps1" and I get an error when I run the job;
ERROR: The term '.\Globals.ps1' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path
ERROR: was included, verify that the path is correct and try again.
ERROR: + CategoryInfo : ObjectNotFound: (.\Globals.ps1:String) [], CommandNotFoundException
ERROR: + FullyQualifiedErrorId : CommandNotFoundException
ERROR: + PSComputerName : localhost
I know how to dot source, so guess I am just wondering if there is something more to it while using the jobtracker.
Thanks, Brian.
Dot Sourcing the globals.ps1 from the JobTracker
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
- brianclark
- Posts: 23
- Last visit: Wed Feb 22, 2023 5:19 pm
Re: Dot Sourcing the globals.ps1 from the JobTracker
The reason for the error is because when running a project, Globals.ps1 is is merged with all project files with the build setting set to include into one script file (ProjectName.Run.ps1). All build settings for project files can be viewed in the Properties panel.
To call an existing function in a job, you need to do something like the following:
To call an existing function in a job, you need to do something like the following:
Code: Select all
$functions = {
function TEST { Write-Output "Hello World" }
}
Start-Job -InitializationScript $functions -ScriptBlock {TEST} | Wait-Job| Receive-Job
Brittney
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.