Getting current directory of the script in PowerShell

Amazing I could find a fast solution for the question “How do I get the current directory of where I run the script”?

The solution is to use like dos command %dp0 but in powershell / .NET syntax:

$currentDirectory = [System.IO.Path]::GetDirectoryName($myInvocation.MyCommand.Definition)

This does the job very nicely but if you have better way please tell me

Getting current directory of the script in PowerShell Getting current directory of the script in PowerShell Reviewed by Ran Davidovitz on 1:44 PM Rating: 5

No comments:

Powered by Blogger.