TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

PowerShell Set-Location

PowerShell Set-Location with What is PowerShell, History of PowerShell, Features of PowerShell, PowerShell vs CMD, PowerShell Scripting, PowerShell Versions, PowerShell Commands, PowerShell Looping, PowerShell Conditions, PowerShell Array, PowerShell Brackets etc.

<< Back to POWERSHELL

PowerShell Set-location | PowerShell Change directory

The Set-Location cmdlet sets the current PowerShell working location to a specified location. The location could be a directory, a registry location, a subdirectory, or any provider path. The sl, cd, chdir are the aliases for the Set-Location cmdlet.

Syntax

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

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

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

Parameters

-Path

The -Path parameter is used to specify a path of the new working location. If no path is provided in the cmdlet, this cmdlet sets the path by default to the current user's home directory. When wildcard characters are used in the cmdlet, it selects the first path that matches the wildcard pattern.

Wildcard keeps a history of the last twenty locations we have set. If the path is the '-'character in the cmdlet, then the new working location becomes a previous working location in history (if it exists). Similarly, if the path is the'+' character in the cmdlet, then the new working location becomes the next working location in history (if it exists). This cmdlet is similar to using Push-Location and Pop-Location cmdlets except that history is a list, not a stack, and there is no way to show this history list.

-LiteralPath

The -LiteralPath parameter is used to specify a path to one or more locations. Its value is used exactly as it is typed. If the path includes the escape characters, enclose it in a single quotation mark. Single quotation mark tells the Windows PowerShell that it should not interpret any character as an escape sequence.

-PassThru

The -PassThru parameter is used to return a PathInfo object, which represents the location. By default, this cmdlet produces any output.

-StackName

The -StackName parameter is used to specify that this cmdlet makes the current location stack. Type the $null or empty string, to indicate the unnamed default location stack. The *-Location cmdlets cannot act on the current stack unless we can use the -StackName parameter to specify the different stack.

Examples

Example 1: To set the current location

PowerShell Set-Location

The example in this cmdlet sets the current location to the root of HKLM: drive.

Example 2: To set the current location and show that location

PowerShell Set-Location

The cmdlet in this example sets the current location to the root of Env: drive. It uses a -PassThru parameter to direct PowerShell to return a PathInfo object, which represents the Env: location.

Example 3: To set the current location to another drive

PowerShell Set-Location

The cmdlet, in this example, sets the current location to the D:drive.






Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf