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, if any?
My research only indicates that the two are basically interchangeable and that one wasn't introduced until PowerShell v3. I have also been told that $MyInvocation.MyCommand.Path
, although not pretty/elegant, has some functionality to it that isn't fully supported by $PSScriptRoot
.
So the overall question is:
Are there any Pros and/or Cons between these two PowerShell commands? Are there instances in which you'd rather use one over the other?
@Mathias R. Jessen: I can understand how you are quick to judge this question; however, it is NOT a duplicate and is especially NOT a duplicate of the question you have pointed this to, which asks "how do I get the root directory". My question isn't HOW do I get the root directory, it is WHAT is the difference in functionality between these two commands. And seeing as you nor anyone else has come back to review my revisions, I am forced to re-ask this question.
For example:
If I am running this script remotely or I am utilizing Jenkins to invoke the base script and I chose to utilize $PSScriptRoot
over $MyInvocation.MyCommand.Path
, would there be a problem or would I essentially have the same exact functionality?
If I have no way to determine whether the server I chose to run the script on has PSv3, but my script was written using PSv3, would using $PSScriptRoot
cause problems?
Thank you in advance.