Reputation: 15
I was given a powershell script by a coworker to try and figure out. I have very little expereince with it so I've gotten stuck.
We need to pull a user defined cmdlet from a .ps1 file form another part of the drive.
Normally you would do it something like this:
. .\scripts\thing.ps1
But we want to use an environmental variable set in command prompt to start the location. We have something like:
. $Env:JobDir\scripts\thing.ps1
But this returns the error
. : The term '\scripts\thing.ps1' is not recognized as the name of a cmdlet, function, script file, or operable program.
Is there anyway to make something like this work?
Upvotes: 0
Views: 47
Reputation: 12248
You can do something like this:
# build the path to the job
$job = Join-path -Path $Env:JobDir -ChildPath "scripts\thing.ps1"
# execute the job
$job
or
.$("$Env:JobDir\scripts\thing.ps1")
Upvotes: 1
Reputation: 1684
You'd need to make it a string, otherwise it's interpreting the entire path as a variable.
"$Env:JobDir\scripts\thing.ps1"
or
$Env:JobDir + "\scripts\thing.ps1"
Upvotes: 3