简体   繁体   English

Powershell ROBOCOPY 用户数据到映射的家庭驱动器

[英]Powershell ROBOCOPY Users Data to Mapped Home Drive

%Username% seems to fail when i would like to deploy this to multiple users.当我想将它部署到多个用户时,%Username% 似乎失败了。 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

您可以检查 UserProfile 环境变量是否有效吗?

Robocopy $env:USERPROFILE\Contacts D:\_Backups\Contacts /xo

%envVariableName% is not the format to use an environment variable. %envVariableName%不是使用环境变量的格式。 $env:variableName is the PowerShell format. $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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM