Running the syntax above in the command line will return a Null exception. It is worth noting that this will only work if you include the syntax above on a saved PowerShell (. The Split-Path cmdlet is used with the -Parent parameter to return the current directory of the running script. Split-Path -Parent $($global:MyInvocation.M圜ommand.Definition) Using the Split-Path Cmdlet to Get the Current Location of the PowerShell Scriptīefore PowerShell 3, there was no better way of querying the MyInvocation.M圜ommand.Definition property by using the Split-Path cmdlet. In this article, we will discuss different ways to get the current location of the running PowerShell script. That way, the script can always find other scripts in the library. Whenever we need to reference a common module or script, we would like to use paths relative to the current script file. Getting the Working Directory in Windows PowerShell to Get the Current Location of the PowerShell Script. Using the $PSScriptRoot Variable to Get the Current Location of the PowerShell Script.Using the Split-Path Cmdlet to Get the Current Location of the PowerShell Script.
0 Comments
Leave a Reply. |