Wednesday, November 1, 2017

Redirect known folders to OneDrive for Business with Powershell

This script will help you migrate user's data for multiple PC's to OneDrive for business and create documentation.

Let's see what you will see in Powershell console during the script execution and what the final html report will look like (note that it depends on what happens during the migration).

I intentionally removed permission from some files in source so that those files can't be migrated so we can see how result will be displayed in a console and final report as well. Beside that I removed permission from already created destination folder so we can see script behavior in that case as well.

Information in powershell console during migration


Final report without errors


Part of final report with some errors




Registry entries that are changed when you redirect user's data to a custom location

These are registry values :

Desktop -  {754AC886-DF64-4CBA-86B5-F7FBF4FBCEF5}
Documents - {F42EE2D3-909F-4907-8871-4C22FC0BF756}
Pictures - {0DDD015D-B06C-45D5-8C4C-F59713854639}
Music - {A0C69A99-21C8-4671-8703-7934162FCF1D}
Videos - {35286A68-3C57-41A1-BBB1-0EAE73D76C95}



Let's see what happens when you run this powershell script

Note: I wanted to predict almost every situation that might happen during migration and I didn't see any problems during testing and actual migrations.  

Please always test or backup files before executing any scripts.

1. It will check current size, locations of  user's known data and open html automatically. This will give us good overview before actually starting migration.

2. If you decide to continue with migration after review, script check if you have multiple OneDrive configured on that PC. If yes, you you will be asked which one to use as a redirection destination. Note that I excluded personal OneDrive and will not be listed here (you can change that if you want to)


3. When you choose which location you are going to use, script checks some prerequisites before migration such as write rights to in destination location etc.

4. If some user's data are already redirected to OneDrive, script will detect that and migration for that user data such as music, videos etc. will be skipped. You should see that in final report as well.


5. If we have some data already stored in destination OneDrive for some reason (we used that location before for data storage etc.) script will copy only newer files to the destination folder.

For example, we already have Music folder in OneDrive with some data in it, but actual Music user folder is not set in OneDrive, only newer files will be migrated. Older files will be left in the source folder for later review or delete. I just didn't want to automatically delete source files after successful migration in this situation. You will see that as partially migrated and  how many files/folders failed to migrate.




The author of this script is not responsible for any damage that might happen.

You can download powershell script here 




No comments:

Post a Comment