
下面的程式碼無法如預期般運作。它將檔案和目錄複製到除預設使用者之外的所有使用者設定檔。我正在以管理員權限執行 Powershell。
$Source = 'C:\Temp\Teste\*'
$Destination = 'C:\users\*\AppData\Local\'
$Default = 'C:\users\Default\AppData\Local\'
Get-ChildItem $Destination | ForEach-Object {Copy-Item -Path $Source -Destination $_ -Force -Recurse}
Get-ChildItem $Default -Force | ForEach-Object {Copy-Item -Path $Source -Destination $_ -Force -Recurse}
答案1
假設您需要將所有檔案和資料夾從來源位置複製到%localappdata%
預設設定檔的位置。
Copy-Item -Path $Source -Destination $Default -Force
遞歸複製(從來源到目標的所有子資料夾和檔案)。
Copy-Item -Path $Source -Destination $Default -Force -Recurse