Powershell filepath for current user's documents folder?

I am trying to copy a file to any current/logged in user’s documents folder, but not sure if the below path is correct?

C:\Users%user%\Documents

Many thanks Tung

Tung,
Welcome to the forum. :wave:t4:

It is not. %user% is CMD syntax and cannot be used in PowerShell.

A variable name in PowerShell usually starts with a dollar sign ($). Environment variables usually start with $Env:. So for your purpose I’d use

"$Env:USERPROFILE\Documents\"

as the target folder.

Hi Olaf,

Thank you! sorry for the newb question, just starting out in PS.

thanks again.

Tung

Could you also use the below?

$Home\Documents

Did you try? :thinking: If not - why not? :wink:

haha im not by my computer, will try tonight thanks

If you are using OneDrive the above solution will not work. Use the following instead:

[Environment]::GetFolderPath('MyDocuments')

1 Like

The special folders used in GetFolderPath include:

AdminTools
ApplicationData
CDBurning
CommonAdminTools
CommonApplicationData
CommonDesktopDirectory
CommonDocuments
CommonMusic
CommonOemLinks
CommonPictures
CommonProgramFiles
CommonProgramFilesX86
CommonPrograms
CommonStartMenu
CommonStartup
CommonTemplates
CommonVideos
Cookies
Desktop
DesktopDirectory
Favorites
Fonts
History
InternetCache
LocalApplicationData
LocalizedResources
MyComputer
MyDocuments
MyMusic
MyPictures
MyVideos
NetworkShortcuts
Personal
PrinterShortcuts
ProgramFiles
ProgramFilesX86
Programs
Recent
Resources
SendTo
StartMenu
Startup
System
SystemX86
Templates
UserProfile
Windows