PowerShell: Get Current Script Path

By Xah Lee. Date: . Last updated: .

get the current script path

# get the current script fullpath
Write-Host $PSCommandPath

# or

Write-Host $MyInvocation.MyCommand.Path

get PowerShell executable path that run the current script

# get PowerShell executable path that run the current script
Write-Host $PSHOME
# C:\Program Files\WindowsApps\Microsoft.PowerShell_7.4.1.0_x64__8wekyb3d8bbwe

get PowerShell version

# get PowerShell version
Write-Host $PSVersionTable.PSVersion
# 7.4.1

# get just the major version string. result is Int32 type
Write-Host $PSVersionTable.PSVersion.Major
# 7

Write-Host $PSVersionTable.PSEdition
# Core

Write-Host $PSVersionTable.OS
# Microsoft Windows 10.0.19045

Write-Host $PSVersionTable.Platform
# Win32NT

PowerShell: Profile and Script