Creating a folder in the current users documents folder through powershell

Hello,

I am working on a script and I will need to create a folder in the current logged in users documents folder. Since the script will be used by multiple users, I will need to directory to be created in C:\Users%UserProfile%\Documents but I’m not sure how to specify that the directory should be created in the current logged in users ‘Documents’ folder… any ideas?

Thanks

You can always use the $Home value to build the directory path where you want to put the folder. The $Home variable contains the path to C:\Users\UserProfile (Ex: C:\Users\user1), for each logged in user. So, you could do something like the following to create the directory.

$Path = "$Home\Documents"
New-Item -Name NewFolder -Path $Path -ItemType Directory

Part of my above explanation text got cut off, so I corrected it with text that didn’t get cleared off.

Exactly what I needed, thank you very much!

Not a problem. Glad I could help. :slight_smile:

The approach with $Home use does not work when the Documents folder is moved to another location.
I had a similar problem and had to use this instead:

[environment]::GetFolderPath("mydocuments")