Josh D'Ambrosio
Josh D'Ambrosio

Reputation: 305

Calling file inside script folder in PowerShell

I have a powershell script in say \Folder\ I then have an exe that I am trying to execute from \Folder\Files\

How can I execute that file without having to specify the whole path and just use either current folder then drill down to Files.

I am trying to use something like this but its not working

Start-Process -FilePath '.\Files\setup.exe' -ArgumentList "-s" -Wait

Upvotes: 0

Views: 4524

Answers (1)

Windos
Windos

Reputation: 1946

The $PSScriptRootvariable will see you right if you're using PowerShell 3 or newer. In version 2 that variable would only work within modules, and I'm not sure about version 1 (before my time.)

$PSScriptRoot gives you the path of the directory in which the script is saved (not the full path including the file name so you don't need to worry about splitting that out.)

For your specific example:

Start-Process -FilePath "$PSScriptRoot\Files\setup.exe" -ArgumentList "-s" -Wait

Upvotes: 1

Related Questions