【问题标题】:Powershell ROBOCOPY Users Data to Mapped Home DrivePowershell ROBOCOPY 用户数据到映射的主驱动器
【发布时间】:2016-06-01 03:12:29
【问题描述】:

当我想将它部署给多个用户时,%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

【问题讨论】:

  • edit 描述您提出的问题或您要解决的问题的标题。除了重复您添加的标签中已有的信息之外,您什么也没做。您的主题应该提供足够的信息,以便对在搜索结果中找到它的未来读者有所帮助。在编辑时,您还可以更清楚地说明您的要求。 %USERNAME% 将完美地适用于当前登录的用户。如果这就是你想要做的,你没有问题。如果不是,你还没有明确说明你想做什么。

标签: powershell robocopy user-profile


【解决方案1】:

你能检查一下 UserProfile 环境变量是否有效吗?

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

【讨论】:

    【解决方案2】:

    %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
    

    【讨论】:

      猜你喜欢
      • 2021-06-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多