Powershell script to create folder based on username and then move profile data

powershell

I am having to create a solution to backup user profiles on a domain (not VDI's) I have the following script that I got to copy the favorites folder, the issue I am having is that I need the script to create a folder based on the username of the person we are backing up and then copy the profile to the folder that was created (based on the username)

I am new on the powershell scripting and haven't been able to find any other solution that does not require the purchase of software.

$destination = "\\backupserver\homedrive$\" 
Copy-Item $env:USERPROFILE\Favorites -Destination $destination -Recurse -Force

Best Answer

If you want to copy the entire user's profile folder, that should include the 'Favorites' folder as well. If that is the case, you could use this.

$destination = 'some destination path'
Copy-Item $env:userprofile -destination $destination -Recurse -force

That should create a folder based on the username.