Sets the current working location to a specified location.

Syntax

Set-Location [-LiteralPath] <string> [-PassThru] [-UseTransaction] [<CommonParameters>]

Set-Location [[-Path] <string>] [-PassThru] [-UseTransaction] [<CommonParameters>]

Set-Location [-StackName <string>] [-PassThru] [-UseTransaction] [<CommonParameters>]

Description

The Set-Location cmdlet sets the working location to a specified location. That location could be a directory, a sub-directory, a registry location, or another location stack.

Parameters

-LiteralPath <string>

Specifies a path to the location. The value of the LiteralPath parameter is used exactly as it is typed. No characters are interpreted as wildcards. If the path includes escape characters, enclose it in single quotation marks. Single quotation marks tell Windows PowerShell not to interpret any characters as escape sequences.

Required?

true

Position?

1

Default Value

none

Accept Pipeline Input?

true (ByPropertyName)

Accept Wildcard Characters?

false

-PassThru

Passes an object representing the location to the pipeline. By default, this cmdlet does not generate any output.

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-Path <string>

This parameter is used to specify the path to a new working location.

Required?

false

Position?

1

Default Value

none

Accept Pipeline Input?

true (ByValue, ByPropertyName)

Accept Wildcard Characters?

false

-StackName <string>

The name of the stack to which the location is being set.

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

true (ByPropertyName)

Accept Wildcard Characters?

false

-UseTransaction

Includes the command in the active transaction. This parameter is valid only when a transaction is in progress. For more information, see about_Transactions.

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

<CommonParameters>

This cmdlet supports the common parameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, -OutBuffer, and -OutVariable. For more information, see about_CommonParameters.

Inputs and Outputs

The input type is the type of the objects that you can pipe to the cmdlet. The return type is the type of the objects that the cmdlet returns.

Inputs

System.String

You can pipe a string that contains a path (but not a literal path) to Set-Location.

Outputs

None or System.Management.Automation.PathInfo

When you use the PassThru parameter, Set-Location generates a System.Management.Automation.PathInfo object that represents the location. Otherwise, this cmdlet does not generate any output.

Notes

The Set-Location cmdlet is designed to work with the data exposed by any provider. To list the providers available in your session, type "Get-PSProvider". For more information, see about_Providers.

Example 1

C:\PS>set-location HKLM:

This will set the current location to the one specified; in this case, it is the HKLM provider.






Example 2

C:\PS>set-location env: -passthru

Path
----
Env:\


Description
-----------
This will set the current location to the one specified; in this case, it is the environment variable provider.






Example 3

C:\PS>set-location C:

This will set the current location to the one specified; in this case, it is the C: drive in the file system provider.






See Also




Table Of Contents