%Username%似乎失败了。有一个更好的方法吗?获取指定用户配置文件的方法是?:
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
答案 0 :(得分:1)
您可以检查UserProfile环境变量是否有效吗?
Robocopy $env:USERPROFILE\Contacts D:\_Backups\Contacts /xo
答案 1 :(得分:0)
%envVariableName%
不是使用环境变量的格式。 $env:variableName
是PowerShell格式。
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