≡ Menu

Find current working directory using PowerShell

What is my current working directory? You can easily determine this if you are in a interactive shell, but how to get this information as part of script. This post will provide that information.

There are two ways available to get the current working directory using PowerShell.

Using cmdlets:

Get-Location returns a object that contains the current path information. You can get it using the command shown below.

Get-Location | select -ExpandProperty Path

Using Dotnet class:

There is a dotnet way available as well. System.IO.Directory class provides this information. All you need to do is invoking the GetCurrentDirectory() method.

[System.IO.Directory]::GetCurrentDirectory()            

Which one you like most?

Comments on this entry are closed.

  • Robert Heritage December 19, 2019, 6:32 pm

    Or just use the command line keyword

    pwd

  • Paul March 10, 2021, 9:49 pm

    (Get-Location).Path