-1

I have a script that I've created to prep our customer's servers for a software install. Part of this requires the script to be run as administrator, so just instructing people to click "Run With Powershell" doesn't get the job done. The script is in a folder with a number of .ini files that the script needs to copy to different server locations. If I just right-click the Powershell script and select "Run With Powershell," it is able to find the files and copy them without issue. Unfortunately, if I open the script in ISE, it opens with a default directory of C:\users\user, and I can't seem to copy those .ini files without first running a change directory command to get us to the folder that the script and the .ini files are in. But I'd like our installation techs to be able to run this without worrying about the exact location they initially drop these folders. I'd also like them to not have to worry about changing the directory manually in PowerShell. Some of our customers have multiple drives, and it might make sense to put this stuff on something other than the C drive, so it's hard to tell where this folder might end up. But I'm not sure of a command that will get me to the directory of the *.ps1 file, without knowing where that file is beforehand... Anyone have a suggestion?

Christopher Cass
  • 817
  • 4
  • 19
  • 31
  • 1
    Possible duplicate of [How can I get the file system location of a PowerShell script?](https://stackoverflow.com/questions/3667238/how-can-i-get-the-file-system-location-of-a-powershell-script) – montonero May 06 '19 at 15:02

1 Answers1

2

You can use $PSScriptRoot that will have the location of the directory where the script is located.

This is referenced in the following post: How can I get the file system location of a PowerShell script?

Shamus Berube
  • 466
  • 3
  • 12