In switching from traditional mapped drives with an assigned drive letter (for example, N:\ or R:\), there are some changes that may need to be made to the way scripts or application preferences are managed.
Scripting with OneDrive
PowerShell is the replacement for both Command and Batch files. PowerShell provides commands that allow one to interact with OneDrive (or other M365 Cloud Storage Locations).
.COM and .BAT files need to be rewritten to use the OneDrive storage location.
Each users local OneDrive cache is located at C:\users\%username%\OneDrive - University of Waterloo\
Some applications cannot work with Environment Variables such as %username%. In those cases, the logged in user will need to set the path using their username in the path.
You may also use the OneDrive “Known Folder Move” feature to enable backup of the Documents folder or the Picture folder to OneDrive.
When Known Folder Move is in use any files in the Documents folder can no longer be referenced via C:\users\%username%\Documents. You will need to use the new path indicated above.
More information about using PowerShell can be found at the Microsoft Learn site
Other Environment Variables for OneDrive
OneDrive can also be referenced by using Microsoft assigned variables:
%OneDriveCommercial% → is used for OneDrive for Organizations accounts. This means one can also use this in scripts: C:\users\%username%\%OneDriveCommercial%
%OneDriveConsumer% → is used for OneDrive Personal accounts i.e., C:\users\%username%\%OneDriveConsumer%
%OneDrive% → will usually access the first OneDrive connection – and if there is only one connection it works as well for scripting.
Working with SharePoint Document Libraries via Scripts
SharePoint Document Libraries can also be accessed via the OneDrive APP.
Once you have a Document Library SYNC setup with your computer, you can use the C-drive SYNC location in your scripts. For example, if I SYNC a Library called Shared Documents, I can reference it in scripts at C:\Users\%username%\University of Waterloo\Shared Documents
For information on using the Document Library SYNC service visit the Microsoft guide
Need help?
Contact the IST Service Desk online or 519-888-4567 ext. 44357.
Article feedback
If you’d like to share any feedback about this article, please let us know.