Creating a folder in the current users documents folder through powershell

This topic contains 4 replies, has 2 voices, and was last updated by  Kevyn 2 weeks, 3 days ago.

  • Author
    Posts
  • #78913

    KD
    Participant

    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

  • #78919

    Kevyn
    Participant

    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
    
    • #78922

      KD
      Participant

      Exactly what I needed, thank you very much!

    • #78973

      Kevyn
      Participant

      Not a problem. Glad I could help. 🙂

  • #78920

    Kevyn
    Participant

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

You must be logged in to reply to this topic.