This topic contains 5 replies, has 3 voices, and was last updated by
September 6, 2017 at 2:18 am #78913ParticipantTopics: 1Replies: 1Points: 0Rank: Member
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?
September 6, 2017 at 3:44 am #78919
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
September 6, 2017 at 3:46 am #78920
Part of my above explanation text got cut off, so I corrected it with text that didn't get cleared off.
January 1, 2018 at 8:50 pm #90590ParticipantTopics: 0Replies: 1Points: 0Rank: Member
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:
The topic ‘Creating a folder in the current users documents folder through powershell’ is closed to new replies.