While working with PowerShell some times if is required to access resources like XML and csv files from local folder where the PS1 file is placed. PowerShell 3.0 has made it easy for us. Use the script below to get current folder, file and execution path
$thisfolderIncludingFileName = Split-Path -parent $MyInvocation.MyCommand.Definition $currentScriptName = $MyInvocation.MyCommand.Name $currentExecutionPath = $thisfolderIncludingFileName.Replace($currentScriptName, ""); Write-Host "Current Folder with FileName : $thisfolder" Write-Host "Current File Name : $currentScriptName" Write-Host "Current Exeuction Path $currentExecutionPath"
Note: I have find out that you must save your script file before you can test these calls and you can not get this path when you press F8 to execute any script line by line.