Set-Location
Use Set-Location to change the current working directory, on any drive a provider exposes.
Documentation: Microsoft Learn — Set-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.
Set-Location [[-Path] <string>] [-PassThru] [-StackName <String>] [<CommonParameters>]- Stage 1Set-Location
-Path -PassThru -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
Set-Location -PassThru
Show reference output
Sample output · fictional data, shaped like the real thing
Path ---- C:\Scripts
Change with Set-Location
Show reference output
Sample output · fictional data, shaped like the real thing
Path ---- C:\Temp
Change with Set-Location (2)
Show reference output
Sample output · fictional data, shaped like the real thing
Path ---- C:\Scripts
Parameters
Parameter definitions:
-Path-PassThru-StackName
Practical use and troubleshooting
Practical scenario: Use Set-Location when you need to change the current working directory, on any drive a provider exposes. 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 path-not-found error can refer to an unavailable drive or provider. Check Get-PSDrive and Test-Path, then use an existing destination appropriate to the intended provider. 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: Get-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
Navigate into the report directory
Create C:\Lab\Reports and make it the working directory.
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
Set-Location Use Set-Location to change the current working directory, on any drive a provider exposes.
Next: Get-Location