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.

2
  • 4
    Why aren't you just recursively copying the root user folder? Commented Aug 30, 2018 at 21:03
  • The desired is to only get the default profile from a user. For instance if a user have another item call "AppData", I would like to exclude that. Commented Aug 31, 2018 at 12:12

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

4 Comments

The exclude remove the RECYCLE bin in new user profile, but inside every folder have RECYCLE.Bin
@Burainu oh .. you're dealing with network share profiles and probably some kind of VDI
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.
Microsoft have a great tool to copy profile from one machine to another .It call usmt learn.microsoft.com/en-us/windows/deployment/usmt/usmt-overview theitbros.com/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.