Folder path of a PowerShell file in PowerShell

powershell

Solution

Try this command in your script:

Split-Path -parent $MyInvocation.MyCommand.Definition

Problem

My PowerShell script file is located in `C:/this-folder/that-folder/another-folder/powershell-file.ps1`. How do I get a variable that returns `C:/this-folder/that-folder/another-folder/`?

Original source