Ask Your Question
2

Can you retrieve the name of the directory the script is currently in using Powershell?

asked 2023-02-01 11:00:00 +0000

ladyg gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2022-11-23 22:00:00 +0000

qstack gravatar image

Yes, the current directory can be retrieved using the built-in variable $PWD (Print Working Directory) in PowerShell.

Here's an example:

$currentDirectory = $PWD.Path
Write-Host "The current directory is: $currentDirectory"

This will output something like:

The current directory is: C:\Users\Username\Documents\PowerShell\Scripts
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-02-01 11:00:00 +0000

Seen: 11 times

Last updated: Nov 23 '22