Export (0) Print
Expand All

Set-Location

Updated: May 8, 2014

Applies To: Windows PowerShell 4.0

Set-Location

Sets the current working location to a specified location.

Aliases

The following abbreviations are aliases for this cmdlet:

  • cd, chdir, sl

Syntax

Parameter Set: Path
Set-Location [[-Path] <String> ] [-PassThru] [-UseTransaction] [ <CommonParameters>]

Parameter Set: LiteralPath
Set-Location -LiteralPath <String> [-PassThru] [-UseTransaction] [ <CommonParameters>]

Parameter Set: Stack
Set-Location [-PassThru] [-StackName <String> ] [-UseTransaction] [ <CommonParameters>]




Detailed 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 any provider path.

You can also use the StackName parameter of the Set-Location cmdlet to make a named location stack the current location stack. For more information about location stacks, see the Notes.

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.


Aliases

none

Required?

true

Position?

named

Default Value

none

Accept Pipeline Input?

true (ByValue, ByPropertyName)

Accept Wildcard Characters?

false

-PassThru

Returns a System.Management.Automation.PathInfo object that represents the location. By default, this cmdlet does not generate any output.


Aliases

none

Required?

false

Position?

named

Default Value

False

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-Path<String>

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


Aliases

none

Required?

false

Position?

1

Default Value

none

Accept Pipeline Input?

true (ByValue, ByPropertyName)

Accept Wildcard Characters?

false

-StackName<String>

Makes the specified location stack the current location stack. Enter a location stack name. To indicate the unnamed default location stack, type "$null" or an empty string ("").

The Location cmdlets act on the current stack unless you use the StackName parameter to specify a different stack.


Aliases

none

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 can only be used when a transaction is in progress. For more information, see about_Transactions.


Aliases

none

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 (http://go.microsoft.com/fwlink/p/?LinkID=113216).

Inputs

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

  • System.String

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


Outputs

The output type is the type of the objects that the cmdlet emits.

  • None, System.Management.Automation.PathInfo, System.Management.Automation.PathInfoStack

    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.

    A "stack" is a last-in, first-out list in which only the most recently added item is accessible. You add items to a stack in the order that you use them, and then retrieve them for use in the reverse order. Windows PowerShell lets you store provider locations in location stacks. Windows PowerShell creates an unnamed default location stack and you can create multiple named location stacks. If you do not specify a stack name, Windows PowerShell uses the current location stack. By default, the unnamed default location is the current location stack, but you can use the Set-Location cmdlet to change the current location stack.

    To manage location stacks, use the Windows PowerShell Location cmdlets, as follows.

    -- To add a location to a location stack, use the Push-Location cmdlet.

    -- To get a location from a location stack, use the Pop-Location cmdlet.

    -- To display the locations in the current location stack, use the Stack parameter of the Get-Location cmdlet. To display the locations in a named location stack, use the StackName parameter of the Get-Location cmdlet.

    -- To create a new location stack, use the StackName parameter of the Push-Location cmdlet. If you specify a stack that does not exist, Push-Location creates the stack.

    -- To make a location stack the current location stack, use the StackName parameter of the Set-Location cmdlet.

    The unnamed default location stack is fully accessible only when it is the current location stack. If you make a named location stack the current location stack, you cannot no longer use Push-Location or Pop-Location cmdlets add or get items from the default stack or use Get-Location command to display the locations in the unnamed stack. To make the unnamed stack the current stack, use the StackName parameter of the Set-Location cmdlet with a value of $null or an empty string ("").

Examples

-------------------------- EXAMPLE 1 --------------------------

This command set the current location to the root of the HKLM: drive.


PS C:\> set-location HKLM:
PS HKLM:\>

-------------------------- EXAMPLE 2 --------------------------

This command sets the current location to the root of the Env: drive. It uses the Passthru parameter to direct Windows PowerShell to return a PathInfo (System.Management.Automation.PathInfo) object that represents the Env: location.


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

Path
----
Env:\
PS Env:\>

-------------------------- EXAMPLE 3 --------------------------

This command sets the current location C: drive in the file system provider.


PS C:\> set-location C:

-------------------------- EXAMPLE 4 --------------------------

This command makes the WSManPaths location stack the current location stack.

The location cmdlets use the current location stack unless a different location stack is specified in the command. For information about location stacks, see the Notes.


PS C:\> set-location -stackName WSManPaths

Related topics



Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft