Powershell - making folder using $env:username

David Novotný 21 Reputation points
2022-02-17T13:54:30.333+00:00

Hello,

I´m new with Powershell and I have script, where I need to make folder using $env:username plus something else - for ex. username is David_N and I need to have folder David_N_Files

I can only make folder called $env:username
Is it possible to make it with Powershell?

Thanks for reply

David Novotny

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,520 questions
0 comments No comments
{count} votes

Accepted answer
  1. MotoX80 33,481 Reputation points
    2022-02-17T15:09:19.91+00:00
    new-item -path "C:\Temp\$($env:USERNAME)_N_Files" -ItemType Directory
    

1 additional answer

Sort by: Most helpful
  1. Ben Kuong 0 Reputation points
    2024-09-29T18:49:28.43+00:00

    new-item -path "C:\Temp$($env:USERNAME)" -ItemType Directory

    Copy-Item -Path "$env:USERPROFILE\AppData\Local\Microsoft\Edge\User Data\Default\Bookmarks" -Destination "C:\Temp$($env:USERNAME)\Edge"

    Copy-Item -Path "$env:USERPROFILE\AppData\Local\Google\Chrome\User Data\Default\Bookmarks" -Destination "C:\Temp$($env:USERNAME)\chrome"

    Add-Content -path C:\Temp\Rollback.ps1 -encoding String 'Copy-Item -Path "C:\Temp$($env:USERNAME)\chrome" -Destination "$env:USERPROFILE\AppData\Local\Google\Chrome\User Data\Default\Bookmarks"

    Copy-Item -Path "C:\Temp$($env:USERNAME)\Edge" -Destination "$env:USERPROFILE\AppData\Local\Microsoft\Edge\User Data\Default\Bookmarks"'

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.