Category filter
Scripts to manage current location on Windows devices
The current working directory refers to the directory in a file system that is currently being accessed and viewed by the user or program. In simpler terms, it is the directory that a user is currently “in” or “working on” in their command prompt or file explorer. Managing the current working directory is a crucial aspect of working with command-line interfaces on Windows devices.
Execute scripts via Hexnode’s Execute Custom Script action to manage the directory locations.
PowerShell commands to manage current location
Get the current location
1 |
Get-Location |
The “Get-Location” command will determine the path of current directory.
Set the current location
1 |
Set-Location -Path [specify path] |
The “Set-Location” command lets you to specify the current location. The “-Path” parameter specifies the new path that you want to set as the current directory location.
The “–PassThru” parameter verifies that a successful directory change has occurred by returning the new location.
E.g., To set the current working directory to ‘C:\Windows’, use this command:
Set-Location -Path C:\Windows -PassThru
Pushing a new location to the stack of directory path
1 |
Set-Location -Path [specify path] |
The “Push-Location” command is used to change the current directory location to a new path. When you execute this command, the current directory location is saved to a location stack, and the new path is set as the current directory location.
E.g., To set the path ‘Media’ to current location ‘C:\Windows’, use this command:
Set-Location -Path C:\Windows
Push-Location -Path "Media" -PassThru
Pop back to last visited location
1 |
Pop-Location |
The “Pop-Location” command pops you back to the recently visited directory.
E.g., The following command will pop you back to the ‘C:\Windows’ directory.
Set-Location -Path C:\Windows
Push-Location -Path "Media"
Pop-Location -PassThru