Powershell复制项问题
我正在尝试将用户配置文件从另一个驱动器复制到我的C:驱动器。我已经记下来了,但我遇到了两个问题,我不断地用我的头撞它们,但对我来说什么都不起作用Powershell复制项问题,powershell,copy-item,Powershell,Copy Item,我正在尝试将用户配置文件从另一个驱动器复制到我的C:驱动器。我已经记下来了,但我遇到了两个问题,我不断地用我的头撞它们,但对我来说什么都不起作用 $user="JohnDoe" Copy-Item -Path "H:\$user\Contacts" -Destination C:\Users\user\Desktop\UserProfile\$user -recurse -Force Copy-Item -Path "H:\$user\Desktop" -Destination C:\User
$user="JohnDoe"
Copy-Item -Path "H:\$user\Contacts" -Destination C:\Users\user\Desktop\UserProfile\$user -recurse -Force
Copy-Item -Path "H:\$user\Desktop" -Destination C:\Users\user\Desktop\UserProfile\$user -recurse -Force
Copy-Item -Path "H:\$user\Documents" -Destination C:\Users\user\Desktop\UserProfile\$user -recurse -Force
Copy-Item -Path "H:\$user\Downloads" -Destination C:\Users\user\Desktop\UserProfile\$user -recurse -Force
Copy-Item -Path "H:\$user\Favorites" -Destination C:\Users\user\Desktop\UserProfile\$user -recurse -Force
Copy-Item -Path "H:\$user\Links" -Destination C:\Users\user\Desktop\UserProfile\$user -recurse -Force
Copy-Item -Path "H:\$user\Music" -Destination C:\Users\user\Desktop\UserProfile\$user -recurse -Force
Copy-Item -Path "H:\$user\Pictures" -Destination C:\Users\user\Desktop\UserProfile\$user -recurse -Force
Copy-Item -Path "H:\$user\Saved Games" -Destination C:\Users\user\Desktop\UserProfile\$user -recurse -Force
Copy-Item -Path "H:\$user\Searches" -Destination C:\Users\user\Desktop\UserProfile\$user -recurse -Force
Copy-Item -Path "H:\$user\Start Menu" -Destination C:\Users\user\Desktop\UserProfile\$user -recurse -Force
Copy-Item -Path "H:\$user\Videos" -Destination C:\Users\user\Desktop\UserProfile\$user -recurse -Force
当我运行代码时,出现的第一个问题是任何先复制的文件夹,它的所有内容都将放在
C:\Users\user\Desktop\UserProfile\$user
例如,在我的代码中,“Contacts”文件夹中的任何内容都将从原始H:驱动器复制到C:驱动器,而不是复制到“Contacts”文件夹中,而是复制到路径位置
C:\Users\user\Desktop\UserProfile\$user
第二个问题是在创建$RECYCLE.BIN的所有文件夹中
如果您能提供一些帮助,我将不胜感激。在这里,我将向函数应用参数哈希表:
$user = 'JohnDoe'
$ciArgs = @{
Path = "H:\$user"
Destination = '~\Desktop\UserProfile\'
Container = $true
Recurse = $true
Force = $true
Exclude = '*$RECYCLE.BIN*'
}
Copy-Item @ciArgs
这将把
$user
文件夹全部复制到UserProfile
文件夹中,跳过回收站隐藏文件夹。为什么不递归复制根用户文件夹?所需的是只从用户处获取默认配置文件。例如,如果用户有另一个项目调用“AppData”,我想将其排除在外。排除将删除新用户配置文件中的回收站,但每个文件夹中都有回收。Bin@Burainu哦您正在处理网络共享配置文件,可能是某种VDI。在使用它之后,排除功能似乎不起作用。我用“桌面”测试了它,但它并不排除桌面。微软有一个很好的工具,可以将配置文件从一台机器复制到另一台机器。它叫usmt