PowerShell Genie

Get-Location

Use Get-Location to return the current working directory for the session.

Command 1 min read Windows PowerShell 5.1 and PowerShell 7

Documentation: Microsoft Learn — Get-Location

Syntax

1PS> Get-Location [-PSProvider <String[]>] [-PSDrive <String[]>] [-Stack] [-StackName <String[]>] [<CommonParameters>]
See the command anatomy

Read the command and its supplied arguments. This example requires real PowerShell or its module; this diagram does not execute it.

Get-Location [-PSProvider <String[]>] [-PSDrive <String[]>] [-Stack] [-StackName <String[]>] [<CommonParameters>]
  1. Stage 1Get-Location-PSProvider -PSDrive -Stack -StackName

    Try it

    Windows PowerShell

    PowerShell example · browser support is limited.

    Execution scope: The full example below requires PowerShell outside this browser. You can edit this runner to use the supported practice commands; unsupported syntax returns an explanation.

    Interactive simulation · fictional data

    Examples

    List all with Get-Location

    1PS> Get-Location
    Show reference output

    Sample output · fictional data, shaped like the real thing

    Path
    ----
    C:\Ops

    Select Path, Provider

    1PS> Get-Location | Select-Object Path, Provider
    Show reference output

    Sample output · fictional data, shaped like the real thing

    Path     Provider
    ----     --------
    C:\Ops   Microsoft.PowerShell.Core\FileSystem

    List all with Get-Location (2)

    1PS> Get-Location; Write-Output 'Script folder is available as $PSScriptRoot inside a script.'
    Show reference output

    Sample output · fictional data, shaped like the real thing

    Script folder is available as $PSScriptRoot inside a script.

    Parameters

    Parameter definitions:

    • -PSProvider
    • -PSDrive
    • -Stack
    • -StackName

    Get-Location on Microsoft Learn

    Practical use and troubleshooting

    Practical scenario: Use Get-Location when you need to return the current working directory for the session. Review syntax and sample output, then try an example in the browser lab. Start with one identified target and inspect the returned values before extending the operation to a list. Keep the identity in your report so you can trace each result back to the object or path that produced it.

    Common error and fix: A report showing the wrong location may reflect a prior Set-Location call. Inspect Path and Provider and prefer explicit paths in unattended scripts instead of assuming the interactive working directory. In an unattended script, capture this failure with its original error record and record which target failed. An empty result and an unsuccessful query must remain distinguishable in the final report.

    See also: Set-Location. Get-Location reports the current provider location; Set-Location changes it. A script that reads relative paths depends on that location unless it supplies a full path. Read the linked command before substituting it; similar names do not imply identical inputs or output.

    Get-Location reference on Microsoft Learn

    Put this command to work

    Find your working directory

    Display the current location as a Path object.

    Review the lesson

    Recap

    Get-Location Use Get-Location to return the current working directory for the session.

    Next: Set-Location
    Genie guideGet-Location

    Use Get-Location to return the current working directory for the session. The console below is pre-loaded — run it, then change a value and run it again.