-1

%Username% seems to fail when i would like to deploy this to multiple users. Is there a better way to do this? A way to get the specified users profile?:

New-Item -ItemType directory -Path O:\_Backups\Contacts
Robocopy C:\Users\%Username%\Contacts O:\_Backups\Contacts /xo

New-Item -ItemType directory -Path O:\_Backups\Desktop
Robocopy C:\Users\%Username%\Dekstop O:\_Backups\Desktop /xo

New-Item -ItemType directory -Path O:\_Backups\Documents
Robocopy C:\Users\%Username%\Documents O:\_Backups\Documents /xo

New-Item -ItemType directory -Path O:\_Backups\Favorites
Robocopy C:\Users\%Username%\Favorites O:\_Backups\Favorites /xo

New-Item -ItemType directory -Path O:\_Backups\Pictures
Robocopy C:\Users\%Username%\Pictures O:\_Backups\Pictures /xo
  • 2
    Please [edit] your title to something that is descriptive of the question you're asking or the problem you're trying to solve. You've done nothing but repeat the information already available in the tags you've added. Your subject should be informative enough to be helpful to future readers who find it among search results. While you're editing, you can also make it more clear what you're asking. `%USERNAME%` will work perfectly for the currently logged in user. If that's what you're trying to do, you don't have a problem. If it's not, you haven't made it clear what it is you want to do. – Ken White Jun 01 '16 at 03:17

2 Answers2

1

Can you check if UserProfile environment variable works?

Robocopy $env:USERPROFILE\Contacts D:\_Backups\Contacts /xo
rawel
  • 2,923
  • 21
  • 33
0

%envVariableName% is not the format to use an environment variable. $env:variableName is the PowerShell format.

New-Item -ItemType directory -Path O:\_Backups\Contacts
Robocopy "C:\Users\$env:username\Contacts" O:\_Backups\Contacts /xo

New-Item -ItemType directory -Path O:\_Backups\Desktop
Robocopy "C:\Users\$env:username\Dekstop" O:\_Backups\Desktop /xo

New-Item -ItemType directory -Path O:\_Backups\Documents
Robocopy "C:\Users\$env:username\Documents" O:\_Backups\Documents /xo

New-Item -ItemType directory -Path O:\_Backups\Favorites
Robocopy "C:\Users\$env:username\Favorites" O:\_Backups\Favorites /xo

New-Item -ItemType directory -Path O:\_Backups\Pictures
Robocopy "C:\Users\$env:username\Pictures" O:\_Backups\Pictures /xo
TravisEz13
  • 2,263
  • 1
  • 20
  • 28