Skip to main content
Active reading.
Source Link
Peter Mortensen
  • 31.4k
  • 22
  • 110
  • 134

PowerShell 3+

# This is an automatic variable set to the current file's/module's directory $PSScriptRoot 

PowerShell 2

Prior to PowerShell 3, there was not a better way than querying the MyInvocation.MyCommand.Definition property for general scripts. I had the following following line at the top of essentially every powershellPowerShell script I had:

$scriptPath = split-path -parent $MyInvocation.MyCommand.Definition 

PowerShell 3+

# This is an automatic variable set to the current file's/module's directory $PSScriptRoot 

PowerShell 2

Prior to PowerShell 3, there was not a better way than querying the MyInvocation.MyCommand.Definition property for general scripts. I had the following line at the top of essentially every powershell script I had:

$scriptPath = split-path -parent $MyInvocation.MyCommand.Definition 

PowerShell 3+

# This is an automatic variable set to the current file's/module's directory $PSScriptRoot 

PowerShell 2

Prior to PowerShell 3, there was not a better way than querying the MyInvocation.MyCommand.Definition property for general scripts. I had the following line at the top of essentially every PowerShell script I had:

$scriptPath = split-path -parent $MyInvocation.MyCommand.Definition 
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link
URL Rewriter Bot
URL Rewriter Bot

PowerShell 3+PowerShell 3+

# This is an automatic variable set to the current file's/module's directory $PSScriptRoot 

PowerShell 2

Prior to PowerShell 3, there was not a better way than querying the MyInvocation.MyCommand.Definition property for general scripts. I had the following line at the top of essentially every powershell script I had:

$scriptPath = split-path -parent $MyInvocation.MyCommand.Definition 

PowerShell 3+

# This is an automatic variable set to the current file's/module's directory $PSScriptRoot 

PowerShell 2

Prior to PowerShell 3, there was not a better way than querying the MyInvocation.MyCommand.Definition property for general scripts. I had the following line at the top of essentially every powershell script I had:

$scriptPath = split-path -parent $MyInvocation.MyCommand.Definition 

PowerShell 3+

# This is an automatic variable set to the current file's/module's directory $PSScriptRoot 

PowerShell 2

Prior to PowerShell 3, there was not a better way than querying the MyInvocation.MyCommand.Definition property for general scripts. I had the following line at the top of essentially every powershell script I had:

$scriptPath = split-path -parent $MyInvocation.MyCommand.Definition 
Paragraph was misleading. It was true at the time it was written "there is not a better way than..." But it is no longer true.
Source Link
Matthew
  • 29.4k
  • 29
  • 107
  • 173

Unfortunately there's not a better way than querying the MyInvocation.MyCommand.Definition property for general scripts. I have the following line at the top of essentially every powershell script I have

PowerShell 3+

# This is an automatic variable set to the current file's/module's directory $PSScriptRoot 

PowerShell 2

Prior to PowerShell 3, there was not a better way than querying the MyInvocation.MyCommand.Definition property for general scripts. I had the following line at the top of essentially every powershell script I had:

$scriptPath = split-path -parent $MyInvocation.MyCommand.Definition 

Unfortunately there's not a better way than querying the MyInvocation.MyCommand.Definition property for general scripts. I have the following line at the top of essentially every powershell script I have

PowerShell 3+

# This is an automatic variable set to the current file's/module's directory $PSScriptRoot 

PowerShell 2

$scriptPath = split-path -parent $MyInvocation.MyCommand.Definition 

PowerShell 3+

# This is an automatic variable set to the current file's/module's directory $PSScriptRoot 

PowerShell 2

Prior to PowerShell 3, there was not a better way than querying the MyInvocation.MyCommand.Definition property for general scripts. I had the following line at the top of essentially every powershell script I had:

$scriptPath = split-path -parent $MyInvocation.MyCommand.Definition 
added 35 characters in body
Source Link
Zombo
  • 1
  • 69
  • 414
  • 436
Loading
added 144 characters in body
Source Link
Aaron Jensen
  • 27.2k
  • 18
  • 85
  • 93
Loading
Source Link
JaredPar
  • 759.3k
  • 152
  • 1.3k
  • 1.5k
Loading