I'm writing a script where the first parameter is a filename. But whenever I try to use that string in something that takes a file, I get an error about the file not being found. How do I get the current directory the powershell prompt is in? For some reason it keeps returning my user profile directory:
C:\Users\user1> [System.IO.Directory]::GetCurrentDirectory()
C:\Users\user1
C:\Users\user1> cd\
C:\> cd temp
C:\temp> [System.IO.Directory]::GetCurrentDirectory()
C:\Users\user1
Type CD drive: to display the current directory in the specified drive. Type CD without parameters to display the current drive and directory. Use the /D switch to change the current drive in addition to changing the current directory for a drive.
Use the pwd command to write to standard output the full path name of your current directory (from the /(root) directory). All directories are separated by a slash (/).
For Windows, cd by itself will show you the current working directory. For UNIX and workalike systems, pwd will perform the same task. You can also use the $PWD shell variable under some shells.
pwd
is the cmdlet you search for ;)
This is an alias for Get-Location
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With