Category Archives: Sharepoint Online

Max Path Length in Sharepoint Online, Onedrive for Business and Teams

Many Office 365 clients (and especially Excel) really don’t like long paths. The older the client, the worse the issues.

To find files over a certain path length in Office 365, I wrote a script a while back. This required manual perusal of the results and manual correction of the issues.

The new version of my script now features fully automatic discovery, a flexible editor and automatic correction of paths based on what you entered into the editor.

Correcting path lengths in Sharepoint Online, Onedrive for Business and Microsoft Teams

You can get the PowerShell script / editor from my git repository here.

Many thanks to CTS in their help me designing and testing this script!

How to use

  1. download the script and save it somewhere
  2. Copy the desired Sharepoint Library into a new Sharepoint Library and/or site
  3. Run the script only for that site by specifying the -specificSiteUrls parameter
  4. do some corrections, commit them, check the results
  5. If satisfied, set permissions for your admin account on the actual production sites your wish to fix (script for Onedrive Mass Permissions here)
  6. Ensure no users have open files in the library
  7. Remove any non-standard characters from folder names (see script source, example code at the top)
  8. Run

Disclaimer

  • Please make sure you TEST this on a copy of your document library/sites before using the ‘commit’ option.
  • Use at your own risk.
  • I recommend turning on the Universal Audit log before usage.

Ultimate folder redirection for Onedrive, Teams and Sharepoint

In the post-Onedrivemapper era where we have Files On Demand, there is still room for improvement in client side configuration of Onedrive for Business. Onedrive Known Folders isn’t up to par yet, doesn’t support any customization and there are situations where I want to be able to redirect local folders to other places than Onedrive like Teams or Sharepoint.

Therefore I present to you “Invoke-O4BAutoMount“; the ultimate Onedrive/Sharepoint/Teams sync and redirect solution in modern workplace scenario’s, no WebDav, just the NSG Onedrive Client and native Intune Management Extension:

Continue reading Ultimate folder redirection for Onedrive, Teams and Sharepoint

Uploading a file to onedrive for business with Python

For a Raspberry Pi project that’ll take a number of pictures of my house for an as of yet unknown period of time I’m sharing my very first Python script with you.

All it has to do is upload all files from a given folder to a given Onedrive for Business path, as obviously the Pi can’t store much data on its tiny SD card. You’ll need to register an azure ad app and give it the appropriate permissions. You’ll have to consent to the application once (url format = https://login.microsoftonline.com/common/adminconsent?client_id={client-id}).

Then the schedule below Python script on your Pi, it will retrieve an Azure token without the need for external libraries, parse the directory and upload everything in it to the given onedrive for business URL, simple as that! It can also be used for Sharepoint or Teams by adjusting the path.

import requests 
import json
directory = r"c:\temp\uploads"
data = {'grant_type':"client_credentials", 
        'resource':"https://graph.microsoft.com", 
        'client_id':'XXXXX', 
        'client_secret':'XXXXX'} 
URL = "https://login.windows.net/YOURTENANTDOMAINNAME/oauth2/token?api-version=1.0"
r = requests.post(url = URL, data = data) 
j = json.loads(r.text)
TOKEN = j["access_token"]
URL = "https://graph.microsoft.com/v1.0/users/YOURONEDRIVEUSERNAME/drive/root:/fotos/HouseHistory"
headers={'Authorization': "Bearer " + TOKEN}
r = requests.get(URL, headers=headers)
j = json.loads(r.text)
print("Uploading file(s) to "+URL)
for root, dirs, files in os.walk(directory):
    for filename in files:
        filepath = os.path.join(root,filename)
        print("Uploading "+filename+"....")
        fileHandle = open(filepath, 'rb')
        r = requests.put(URL+"/"+filename+":/content", data=fileHandle, headers=headers)
        fileHandle.close()
        if r.status_code == 200 or r.status_code == 201:
            #remove folder contents
            print("succeeded, removing original file...")
            os.remove(os.path.join(root, filename)) 
print("Script completed")
raise SystemExit

Reporting on global tenant storage usage and per site storage usage

As my employer is a Microsoft Cloud Service Provider, we want to monitor the total storage available and the total storage used by all of the tenants we manage under CSP, including storage used by Sharepoint and Teams. This called for a script!

per customer total storage usage overview

I slimmed down the resulting script to work for just a single tenant that you can use to generate an XLSX report of which of your sites / teams are nearing their assigned storage quota. You can either build your own alerting around this to raise site quota’s before your users upload too much data, or you can use it to buy additional storage from Microsoft before your tenant reaches the maximum quota 🙂

per site storage overview in excel

As usual, find it on Gitlab!