Linked Questions

65 votes
7 answers
94k views

I want to be able to tell what path my executing script was run from. This will often not be $pwd. I need to call other scripts that are in a folder structure relative to my script and while I could ...
Kevin Buchan's user avatar
  • 2,908
67 votes
1 answer
160k views

I run a PowerShell script. How do I get the directory path of this script I run? How to do this?
user2131116's user avatar
  • 2,881
71 votes
4 answers
129k views

How do I do this in PowerShell. In a batch file I would do: %~d0%~p0
user avatar
2 votes
1 answer
5k views

I am trying to have powershell spit out the output file from a command to the current folder as I am trying to create a printer migration that can be run from a USB stick. My command is simply: C:\...
Chase Mostat's user avatar
2 votes
0 answers
4k views

I am using a PowerShell file. I have a file inside the same folder, path can change but folder remains same. How to use relative path, so there is no change in script? Param([string]$servername, [...
deepti's user avatar
  • 729
2 votes
0 answers
587 views

Edited to better explain overall question: In PowerShell, what is the difference between using $MyInvocation.MyCommand.Path and $PSScriptRoot for acquiring the running script's current root directory,...
Brandon's user avatar
  • 771
286 votes
20 answers
572k views

This should be a simple task, but I have seen several attempts on how to get the path to the directory where the executed cmdlet is located with mixed success. For instance, when I execute C:\temp\...
Stig Perez's user avatar
  • 3,883
68 votes
4 answers
106k views

I have a PowerShell script located at D:\temp. When I run this script, I want the current location of the file to be listed. How do I do this? For example, this code would accomplish it in a DOS ...
Santhosh's user avatar
  • 6,707
9 votes
3 answers
16k views

Problem I am working with Jenkins to deploy PowerShell scripts remotely. As such, I am trying to figure out if there will be problems utilizing $PSScriptRoot over $MyInvocation.MyCommand.Path for ...
Brandon's user avatar
  • 771
10 votes
1 answer
25k views

I have a script (script1.ps1) that lies in C:\FolderA What powershell code can I insert in the script, that it will print what ever current location/path of the script. (The goal is to make this ...
AdilZ's user avatar
  • 1,237
9 votes
5 answers
17k views

EDIT: To future readers, in short, PowerShell scripts weren't intended to be used this way which is why there is no elegant solution. I have the following line which runs a script as an administrator ...
Jesse Good's user avatar
  • 52.8k
3 votes
1 answer
13k views

I have this: Get-ChildItem c:\H\admin\contents Is it possible to do the same thing but relative to the folder that the powershell script runs in. Sometimes I have the script running in c\H\admin ...
user avatar
3 votes
1 answer
3k views

I created my ps1 script and to get the path dynamically I used this command $ScriptPath = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent Everything works fine when I use ISE console but ...
Gus's user avatar
  • 953
2 votes
3 answers
2k views

How can I get a remotely executed script to know it's own location? I'm using Invoke-Command to run a script on a remote server. The script needs to create files in the directory in which it lives. ...
Richard Schaefer's user avatar
0 votes
1 answer
5k views

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 ...
Josh D'Ambrosio's user avatar

15 30 50 per page