Manage Sharepoint Online and OneDrive with Powershell

Hi all! I am planning a project to deploy Sharepoint Online to both faculty and students at a K-12 school. We have certain needs for this and the provided Powershell Module is not meeting those needs.

First my goals:

1. Provide cloud file storage with sharing/collaboration

2. Report on the environment and prevent abuse

Goal 1 is obvious - I can just assign Sharepoint licenses and users will have OneDrive Pro to store files in.

Goal 2 is a bit harder. Once a user has a SP license they have essentially been transported to the Wild West. They are provisioned a personal site with full control meaning they can share with anyone and create subsites under that site. One thing I have tested is removing the user from the site collection adminstrators which prevents creation of subsites. I can then grant them Edit permissions which still allows sharing and modification but this cannot be done in bulk. So I am left with two sub-goals:

1. How to discover all sites

2. Setting permissions on all these sites

I landed on the Sharepoint Client Components SDK to try to bridge this gap. For background, I manage our AD, MSOL, and Exchange Online and am fairly well versed in Powershell. However, I'm nearly clueless on the Sharepoint side so I don't want to waste too much time barking up the wrong tree. So far with the SDK I can enter a URL for a site that I have permission to and return the site properties, but that's about all. I am still working through some of the C# examples and to determine exactly how I would enumerate all the sites (particularly personal sites and their subsites if any) and set permissions on those sites. Has anyone else done anything like this or do you have any methods you could recommend? Thanks!

May 9th, 2014 3:54pm

EDIT: As a secondary question, does anyone think it might be possible to achieve any of this with REST?
Free Windows Admin Tool Kit Click here and download it now
May 9th, 2014 6:29pm

You can edit the top ribbon bar and remove the sites option for each student using the visual studio. Try customizing SharePoint ribbon.

Check these few articles :

How to add a security trimming for your ribbon

http://msdn.microsoft.com/en-us/library/office/jj822366(v=office.15).aspx

Basics of creating a custom ribbon using xml and js http://www.sharepointnutsandbolts.com/2010/01/customizing-ribbon-part-1-creating-tabs.html

hide ribbion js code in content editior

http://social.msdn.microsoft.com/Forums/sharepoint/en-US/b052f0ca-9d2a-4ddc-97d7-4e017a4d5f76/customising-the-ribbon?forum=sharepointcustomizationprevious

Ribbon Customisation from visual studio

http://blogs.msdn.com/b/sharepointdev/archive/2012/04/30/how-to-hide-the-ribbon-in-sharepoint-2010-rajeswari-mohandas.aspx If you find this helpful please propose this as answer and vote. Thanks.

May 9th, 2014 6:41pm

Thanks for the info, but I am failing to see how his meet the goals as stated above. These documents all demonstrate how to publish a ribbon item to users, but I don't see how any of this could apply to discovering the sites or setting permissions. Did I miss something?

Thanks again!

Free Windows Admin Tool Kit Click here and download it now
May 9th, 2014 7:17pm

I need to find out how to do the same: How do I get a list of all users who have a OneDrive provisioned? Powershell would be the best option for me. 

All I can figure out is get-msoSite [siteurl]

But then I have to know the email of every user who has one.

June 11th, 2014 3:14pm

I need to find out how to do the same: How do I get a list of all users who have a OneDrive provisioned? Powershell would be the best option for me. 

All I can figure out is get-msoSite [siteurl]

But then I have to know the email of every user who has one.

You can do that with the Msonline cmdlets by querying anyone with a sharepoint license:

$Users = get-msoluser -All

foreach ($User in $Users)
{
    Foreach ($Plan in $User.Licenses.ServiceStatus)
    {
        if (($Plan.servicePlan.servicename -like 'Share*') -and $Plan.ProvisioningStatus -eq 'Success')
        {
            $User
        }
    }
}
Not very elegant but works.

Free Windows Admin Tool Kit Click here and download it now
June 11th, 2014 6:00pm

Thank you Matt! That is just what I needed. Below is the finished script that outputs how much space each user has used in their My Site/OneDrive , and outputs N/A if they haven't created one yet, but do have a license assigned.

cls
Connect-MsolService 

$urlPrefix="https://tenant-my.sharepoint.com/personal/"
$users=get-msoluser -All
$usercount=0
$oneDriveCount=0
foreach ($user in $users){
    Foreach ($Plan in $User.Licenses.ServiceStatus){
        if (($Plan.servicePlan.servicename -like 'SharepointEnterprise') -and $Plan.ProvisioningStatus -eq 'Success')
        {   
            $usercount++         
            try{
                $url=$urlPrefix + $user.UserPrincipalName.Replace(".","_").Replace("@","_")
                $OneDrive=Get-SPOSite $url 
                [string]::Format("{0},{1}",$user.UserPrincipalName,$onedrive.StorageUsageCurrent)
                $oneDriveCount++                
               
            }catch{
                [string]::Format("{0},N/A",$user.UserPrincipalName)
            }
        }
    }
}
[string]::Format("OneDrives:{0}`nProfiles{1}",$oneDriveCount,$userCount)

June 11th, 2014 7:29pm

Hi,

Did this script work? I am getting an error with Get-SPOSite when trying to get the OneDrive site. "Cannot get site https://domain-my.sharepoint.com/personal/firstname_lastname_domain_com 

Any suggestions? 

Thanks,

Nilaish

Free Windows Admin Tool Kit Click here and download it now
July 3rd, 2014 6:40pm

My Script (jj_the_skeptic) did work for me - it will throw an error if a user hasn't created a OneDrive yet- maybe that is your issue? could be the error handling options you have turned on in Powershell?
July 3rd, 2014 8:12pm

Nilaish: the script is no longer working for me now either. Microsoft Support tells me that use of the get-SPOSite command is not supported at the moment, but will be re-released shortly

From MS Support on 7/9/2014:

The product team has confirmed the capability to retrieve OneDrive site information was not intended to be available.  There was a change that occurred last week for site collection quota metric calculation formatting (change from MB to GB) which inadvertently closed the ability to use get-spsite cmdlet to retrieve personal site collections.  The product team was previously working on a new set of PowerShell commands for O365 that provide the ability to retrieve OneDrive information.  They have completed their testing and are waiting for the team that creates the client installation packages and documentation to complete their work and get the packages out to the download center.  I apologize that I dont have the exact timing for when this should be available but I am told it is their highest priority to get these released.   Once the new package is released, they will provide the ability to query the sites and attributes.

Free Windows Admin Tool Kit Click here and download it now
July 10th, 2014 7:03pm

This is fantastic! Thanks for the update - I really hope to see this released soon as this will satisfy our needs to discover personal sites. Hopefully they let us get our hands dirty with permissions and settings on personal sites as well.
July 10th, 2014 7:16pm

Hi, Does anyone have any update from Microsoft concerning the updated Powershell commands ?


Free Windows Admin Tool Kit Click here and download it now
August 11th, 2014 9:36am

Unfortunately I haven't heard anything new on this front.

Hi, Does anyone have any update from Microsoft concerning the updated Powershell commands ?



August 12th, 2014 11:26pm

Like others I just wanted to echo that we are sorely in need of tools to manage user adoption of O365 technology.

 - With OneDrive for Business it's hard to fathom how businesses can not have a method to report on storage use for each user - having 1 TB is great, but how can we tell who is actually using their OneDrive without seeing that the storage for each user. The lack of a tool to easily move content from one former employee's OneDrive to another employee's is also a glaring hole - it can be done with a lot of work but should be as simple as a checkbox and selector field with a Go Do It button

 - With Lync Online we also can not see at a user level who is actually using Lync; all the reporting tells us is as a whole how many total sessions, meetings, etc.

 - With Exchange Online we have no way to centrally administer users photos with the same capability as a user has (being able to upload a photo and have it resized to meet each individual services needs). The only option now is to go with the poor quality 10 KB max photos and try to push it in through powershell.

Seems like making the services business-friendly would be a big bullet point on the O365 roadmap.....

Free Windows Admin Tool Kit Click here and download it now
September 18th, 2014 4:46pm

Are there any updates on being able to see the size of the OneDrive sites provisioned at my company?  Thanks!
December 3rd, 2014 11:08pm

You can use following CSOM based code to pull usage of onedrive site (of course, you will need to customize your code to make it easy like need to pull all onedrive site URL using userprofile library and then after need to loop following code to find storage for each onedrive site + targetuser that you use should have site collection admin access to connect and find storage of onedrive site)

            const string serverUrl = "https://tenant-my.sharepoint.com/personal/user_tenant_onmicrosoft_com";
            const string targetUser = "adminuser@tenant.onmicrosoft.com";

            using (ClientContext ctx = new ClientContext(serverUrl))
            {

                Random ran = new Random();

                SecureString passWord = new SecureString();

                foreach (char c in "mypassword".ToCharArray()) passWord.AppendChar(c);

                ctx.Credentials = new SharePointOnlineCredentials(targetUser, passWord);

                Site site = ctx.Site;

                ctx.Load(site, s => s.Usage, s => s.Url);

                ctx.ExecuteQuery();

                UsageInfo usageInfo = site.Usage;

                Console.WriteLine(" Site URL is {0} ", site.Url);                

                Console.WriteLine(" Storage used in GB {0} ", usageInfo.Storage/1024d/1024d/1024d);                
            }

Free Windows Admin Tool Kit Click here and download it now
January 14th, 2015 11:41am

SharePointKing,

Thanks for the help, but I'm really wanting a way to do this in Powershell rather than in C#. Powershell doesn't seem to work too well with CSOM because it doesn't support Generics - at least that's what I've been told.

I can't imagine an organization that would think it's ok that anyone can create a website in their domain and post any content to it that they like with no way to audit. That's essentially what Sharepoint Online does.

I really need to be able to discover all the sites that have been created in our tenant. If anyone knows a way to do this, please reply. Thanks!

January 14th, 2015 12:48pm

Count me in. We need some way to manage OD using PS also.  This "we'll catch up" thing that MS does, really bites. Is O365 Enterprise ready or not?

Free Windows Admin Tool Kit Click here and download it now
February 11th, 2015 2:27pm

Same here, I need the ability to easily pull the amount of data a user has stored in their OD4B. I would also like to see a way to move an expired users OD4B site to another user so it does not get purged after 30days.

February 24th, 2015 10:09pm

Nilaish: the script is no longer working for me now either. Microsoft Support tells me that use of the get-SPOSite command is not supported at the moment, but will be re-released shortly

From MS Support on 7/9/2014:

The product team has confirmed the capability to retrieve OneDrive site information was not intended to be available.  There was a change that occurred last week for site collection quota metric calculation formatting (change from MB to GB) which inadvertently closed the ability to use get-spsite cmdlet to retrieve personal site collections.  The product team was previously working on a new set of PowerShell commands for O365 that provide the ability to retrieve OneDrive information.  They have completed their testing and are waiting for the team that creates the client installation packages and documentation to complete their work and get the packages out to the download center.  I apologize that I dont have the exact timing for when this should be available but I am told it is their highest priority to get these released.   Once the new package is released, they will provide the ability to query the sites and attributes.

JJ: Any update on this yet? I see that a new version of the module was released recently, but can't figure out what it's capabilities are for Onedrives. It seems it can find them just fine, but doesn't really give me any new options for controlling them. If it just had ways to manage permissions I would be a happy camper.
Free Windows Admin Tool Kit Click here and download it now
March 15th, 2015 1:06am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics