This script comes with a large security warning.

 

This code as it sits requires username/password as a secure string.  While this is slightly better than clear text, it presents a large risk if the PS1 was stored somewhere accessible.  The other option is to save the secure string and read that file in (with proper ACLs) or if not using as a scheduled task, change the script to prompt for read-host -asSecureString

 

Tested against Office 365, with SharePoint Online identities (via ADFS as well) - Live ID's do not seem to work, still investigating that.

 

Also, it REQUIRES two DLL files.  I wish it didn't.  Couldn't find a way with the CSOM to do it.

 

I included them in the ZIP, but they are available free via the SharePoint SDK.