Get-Location
Use Get-Location to return the current working directory for the session.
Documentation: Microsoft Learn — Get-Location
Syntax
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>]- Stage 1Get-Location
-PSProvider -PSDrive -Stack -StackName
Try it
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.
Follow the objects
Run the command to inspect each stage.
Examples
List all with Get-Location
Show reference output
Sample output · fictional data, shaped like the real thing
Path ---- C:\Ops
Select 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)
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
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.
Put this command to work
Find your working directory
Display the current location as a Path object.
The sandbox is visible now. Sign in with Google only when you run or check a task; commands and temporary files are discarded when you leave.
Run a command to inspect its result.
Inspect starting data
Supported syntax
Virtual files
Recap
Get-Location Use Get-Location to return the current working directory for the session.
Next: Set-Location