Link to home
Start Free TrialLog in
Avatar of Member_2_2862251
Member_2_2862251

asked on

Powershell relative path variable for software installation

Quick question.

I'm trying to do more with Powershell with regard to installing software. However, we have multiple sources for software so using absolute paths (ex. \\server01\software\package.exe) is not a good option. When creating Windows batch files I've found that using %~dp0 is enough to tell the script to search the folder it's in or one below, such as:

"%~dp01\Software\Version\setup.exe"

I've looked online for a Powershell equivalent, the closest I've found is $PSScriptRoot. But it relates to scripts and not to launching EXE or MSI files (as I understand it).

Short version, is there's a relative path variable cmdlet that can be used when pointing to an executable?
Avatar of J0rtIT
J0rtIT
Flag of Venezuela, Bolivarian Republic of image

Yes the shot one is:
$global:ScriptLocation = $(get-location).Path

Open in new window


And then use the $global:ScriptLocation variable on any function or point in your script.
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Well, @oBdA I have used that shortcut on every of my scripts to find the local path of the script where the script is actually running, and that's my suggested solution if you just have anything to add just do it. did you even try it?. of course he's not running his MSI or EXE files from an AD path...
I have more than 8k of downloads and more than 10 endorsements with 4 stars or more on TechNet.
Jose, oBdA is correct; maybe you misread the question. The Asker is searching for the equivalent for "%~dp0", and that is the script path, not the current working directory ("where the script is actually running" vs. "where the script is actually stored").
Ohh Ok then, please remember to mark the answer as correct if he or I provided a solution that suits you.