How to Use PowerShell to Navigate the Windows Folder Structure

Learn these PowerShell commands to move quickly around Windows folder structures.

Brien Posey

August 15, 2022

4 Min Read
How to Use PowerShell to Navigate the Windows Folder Structure
Getty Images

PowerShell uses several commands to navigate the Windows folder structure.

When you open a new PowerShell window, PowerShell usually starts you in your user profile directory. In Figure 1, for example, you can see that the PowerShell prompt is pointing to C:UsersBrien. Although the user profile has its place, PowerShell operations often require you to navigate to a different location within the folder hierarchy. In my case, most of my PowerShell scripts are located in a folder called C:Scripts and are inaccessible from the user profile folder.

UsersBrien

PowerShell Navigation 1

Figure 1. PowerShell often opens to your user profile folder.

In this article, I will explain how to navigate the Windows folder structure using PowerShell.

Switching Drives

In PowerShell-based navigation, the first thing to know is how to switch to different drives.

To change drives, just enter the drive letter you want to go to, followed by a colon. In Figure 2, for example, I switched from the C: drive to the Q: drive by typing Q:. I then switched back to the C: drive by typing C:.

 drive

PowerShell Navigation 2

Figure 2. You can switch drives by entering the drive letter and a colon.

CD.. and CD Commands

Most file system navigation involves traversing the directory structure. If you want to drop down one level within the directory hierarchy, you can do so by typing CD.. (note that there are two periods).

Related:Use PowerShell To Find Password-protected Word Documents

If you look back at the previous two figures, you can see that PowerShell initially placed me in the C:UsersBrien folder. By entering CD.., PowerShell would drop me down to the C:Users folder.

Although you can use the CD.. command to move through the folder hierarchy one level at a time, it’s not always the most efficient method. For example, if I were in the C:UsersBrien folder and needed to drop down to the root folder, I could enter the CD.. command twice, as I have done in Figure 3.

PowerShell screen shows the use of CD.. command to go to root folder

PowerShell Navigation 3

Figure 3. Typing CD.. moves you down a level in the folder hierarchy.

However, as a shortcut, I could enter the CD command. That would immediately drop me down to the root folder. Figure 4 provides an example.

PowerShell screen shows the use of CD to go to root directory

PowerShell Navigation 4

Figure 4. Typing CD causes PowerShell to move to the root directory.

As you can see, you can use the CD.. or CD command to move to a lower level within the folder hierarchy. You can also use the CD command to enter a folder. Just type CD, followed by the folder name. If I were in the C:Users folder and wanted to navigate to the Brien subfolder, I could type CD Brien.

PowerShell Aliases

Note that even though this article discusses the CD command, CD is not a “real” PowerShell command. In the days of DOS, CD was the command used to traverse the directory structure. Microsoft has included support for the CD command in PowerShell both as a shortcut and way of making PowerShell a bit more like DOS.

The CD command is what is known as an alias.

In PowerShell, an alias is essentially just a shortcut. It’s a shortened command that takes the place of a longer command. The longer command (which PowerShell calls a cmdlet) for which CD is an alias is Set-Location.

The Set-Location cmdlet works identically to the CD command, with one minor caveat. Unlike the CD command, you must include a space after the Set-Location cmdlet. Whereas CD.. is a valid command, Set-Location.. is not. Instead, to avoid receiving an error, you would have to type:

Set-Location ..

You can see this in Figure 5.

PowerShell screen shows use of Set-Location .. command

PowerShell Navigation 5

Figure 5. The CD command is an alias for Set-Location.

Get-ChildItem and DIR Commands

There is one more PowerShell cmdlet that is useful when navigating the Windows folder structure: Get-ChildItem.

The Get-ChildItem cmdlet displays the contents of the current folder. It’s helpful if you want to navigate to a subfolder but aren’t sure of the exact folder name.

Incidentally, the Get-ChildItem cmdlet also has an alias. The alias is DIR, which also originates from the days of DOS. Back then, DIR was the DOS Directory command. You can see how the DIR command works in Figure 6.

PowerShell screen shows use of DIR command

PowerShell Navigation 6

Figure 6. You can use the DIR command to see the current folder’s contents.

So, with that in mind, suppose that I needed to navigate to the C:UsersBrienDesktop folder but couldn’t remember the name of the Desktop folder. I could navigate to C:UsersBrien, then use either the DIR or the Get-ChildItem cmdlet to see a list of all of the files and folders in that location. I could then use that information to get the name of the folder that I need (in this case, Desktop) and navigate to it using the CD command.

About the Author

Brien Posey

Brien Posey is a bestselling technology author, a speaker, and a 20X Microsoft MVP. In addition to his ongoing work in IT, Posey has spent the last several years training as a commercial astronaut candidate in preparation to fly on a mission to study polar mesospheric clouds from space.

http://brienposey.com/

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like