2

I am trying to copy a user's profile from another drive to my C: drive. I have it down, but I ran into two problems that I keep banging my head against, but nothing is working for me.

$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 

When I ran the code, the first problem that happen is any folder that is copy first, all it's contents will be put inside the

 C:\Users\user\Desktop\UserProfile\$user

In my code for instance, any contents in the "Contacts" folder from the oringial H: Drive will be copy over to C:Drive not inside the "Contacts" folder, but in the path location

 C:\Users\user\Desktop\UserProfile\$user

The second problem is in all the folders $RECYCLE.BIN is created.

Inside the C:Drive path folder


Inside the C:Drive path folder\Favorites

Some help would be appreciate it.

Maximilian Burszley
  • 18,243
  • 4
  • 34
  • 63
Burainu
  • 35
  • 4

1 Answers1

1

Here, I'ved used a feature called Splatting to apply a hashtable of parameters to the function:

$user = 'JohnDoe'

$ciArgs = @{
    Path        = "H:\$user"
    Destination = '~\Desktop\UserProfile\'
    Container   = $true
    Recurse     = $true
    Force       = $true
    Exclude     = '*$RECYCLE.BIN*'
}
Copy-Item @ciArgs

This will copy the $user folder to your UserProfile folder in its entirety, skipping the recycle bin hidden folder.

Maximilian Burszley
  • 18,243
  • 4
  • 34
  • 63
  • The exclude remove the RECYCLE bin in new user profile, but inside every folder have RECYCLE.Bin – Burainu Aug 31 '18 at 12:20
  • 1
    @Burainu oh .. you're dealing with network share profiles and probably some kind of VDI – Maximilian Burszley Aug 31 '18 at 12:28
  • After playing around with it, it seems the exclude does not seem to function. I tested it with "Desktop", but it's not excluding desktop. – Burainu Aug 31 '18 at 12:33
  • Microsoft have a great tool to copy profile from one machine to another .It call usmt https://learn.microsoft.com/en-us/windows/deployment/usmt/usmt-overview https://theitbros.com/migrate-user-profiles-with-user-state-migration-tool-usmt/ – Bonneau21 Aug 31 '18 at 14:30