I'm trying to work out a process that would allow my helpdesk to delete an individual user's profile from Office 365 sharepoint online using powershell.
It's easy to connect to our Sharepoint Online URL and see the sites we have:
Connect-MsolService
Connect-SPOService -url https://example-admin.sharepoint.com -Credential [email protected]
I can verify that I'm connected.
get-sposite
returns a list of our sharepoint online URLs, as you expect.
Running commands such as repair-sposite
or remove-sposite
work for the entire site collection, e.g. repair-sposite -identity https://example-my.sharepoint.com
works on the whole site collection, so the last thing I want to be doing is running remove-sposite
at this level, and running it at a deeper level (repair-sposite -identity https://example-my.sharepoint.com/personal/user_example_com
) fails to locate a sharepoint site to work with.
There are a few sites out there that have all cut and pasted the same snippet of code to iterate all the users in a sharepoint mysites collection and remove all of them, but I'm not convinced that code works for sharepoint 2013 sites and it's trivial to remove a user's permissions from a site. But I don't want to do either of those things, I just want to remove one user's profile from mysites.
Best I can find for you:
http://jopx.blogspot.com/2013/08/managing-sharepoint-online-with.html
Which states:
But then gives this possibility:
But isn't what you are after for providing a simple PS script for the Helpdesk to use. You might consider opening a ticket with O365 support, but my experience with that has been hit or miss. Sometimes it seems I get someone that knows only scripted answers, and then there are times where it seems I get the actual developers themselves.
I've been generating a library to use for sharepoint online, so I've been writing hundreds of these small tasks lately, but basically you'll need to use CSOM commands. first, download the sharepoint server 2013 client context SDK. Then make sure you include the DLL in your code:
Import-Module 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll'
Your path to the DLL may differ from mine.
Now you can use CSOM to do just about anything you want.
Here's some code that should accomplish what you're trying to do.