SharePoint Online: How to do a bulk creation of ODFB Sites using PowerShell!

One of the new features added by Microsoft over the past year to the client object model (CSOM) SharePoint is the possibility of doing massive and asynchronous provisioning of OneDrive To Business (ODFB) sites using the CreatePersonalSiteEnqueueBulk () method of the class ProfileLoader defined in Microsoft.SharePoint.Client.UserProfiles.dll assembly of the CSOM. This method simply requires an array of strings with the e-mails of the Office 365 users we want to be provision ODFB sites as you can see in the script that I created about:  How to do a bulk creation of OneDrive For Business sites in Office 365

############################################################################################################################################

#Script that allows to asynchronously provision OneDrive For Business for a set of users

# Required Parameters:

#  -> $sCSOMPath: Path for the Client Side Object Model for SPO.

#  -> $sUserName: User Name to connect to the SharePoint Online Site Collection.

#  -> $sPassword: Password for the user.

#  -> $sSiteUrl: SharePoint Online Administration Url.

#  -> $ODFBUser: Office 365 user .

############################################################################################################################################

 

$host.Runspace.ThreadOptions = "ReuseThread"

 

#Definition of the function that allows to provision ODFB for a set of users

function Create-ODFBSite

{

    param ($sCSOMPath,$sSiteUrl,$sUserName,$sPassword,$sODFBUsers)

    try

    {    

        Write-Host "----------------------------------------------------------------------------"  -foregroundcolor Green

        Write-Host "Getting the User Profile Information for current user" -foregroundcolor Green

        Write-Host "----------------------------------------------------------------------------"  -foregroundcolor Green

                    

        #Adding the Client OM Assemblies

        $sCSOMRuntimePath=$sCSOMPath +  "\Microsoft.SharePoint.Client.Runtime.dll"  

        $sCSOMUserProfilesPath=$sCSOMPath +  "\Microsoft.SharePoint.Client.UserProfiles.dll"        

        $sCSOMPath=$sCSOMPath +  "\Microsoft.SharePoint.Client.dll"             

        Add-Type -Path $sCSOMPath         

        Add-Type -Path $sCSOMRuntimePath

        Add-Type -Path $sCSOMUserProfilesPath

 

        #SPO Client Object Model Context

        $spoCtx = New-Object Microsoft.SharePoint.Client.ClientContext($sSiteUrl) 

        $spoCredentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($sUserName, $sPassword)  

        $spoCtx.Credentials = $spoCredentials        

        $spoUserProfilesLoader=[Microsoft.SharePoint.Client.UserProfiles.ProfileLoader]::GetProfileLoader($spoCtx)     

        $spoUserProfilesLoader.CreatePersonalSiteEnqueueBulk($sODFBUsers)

        $spoUserProfilesLoader.Context.ExecuteQuery()

        $spoCtx.Dispose()

    }

    catch [System.Exception]

    {

        write-host -f red $_.Exception.ToString()   

    }    

}

 

#Required Parameters

$sSiteUrl = "https://<SPO_Site_Url>/" 

$sUserName = "<SPOUser>@<SPO_Domain>.onmicrosoft.com" 

$sPassword = Read-Host -Prompt "Enter your password: " -AsSecureString

$sCSOMPath="<CSOM_Path>"

$sODFBUsers="<SPOUser1>@<SPO_Domain>.onmicrosoft.com","<SPOUser2>@<SPO_Domain>.onmicrosoft.com"

 

Create-ODFBSite -sCSOMPath $sCSOMPath -sSiteUrl $sSiteUrl -sUserName $sUserName -sPassword $sPassword -sODFBUsers $sODFBUsers

To verify that the ODFB sites have been provisioned I recommend the following post of Thomas Balkeståhl: http://blog.blksthl.com/2014/08/08/office-365-guide-series-verify-provisioned-onedrives-using-powershell/

SharePoint Online: Como provisionar de forma masiva ODFB para varios usuarios!

Una de las novedades que incorporó el modelo de objetos en cliente (CSOM) de SharePoint durante el año pasado es la posibilidad de realizar el provisionado masivo y asíncrono de sitios de OneDrive Para Empresas (ODFB) haciendo uso del método CreatePersonalSiteEnqueueBulk() de la clase ProfileLoader definida en el ensamblado Microsoft.SharePoint.Client.UserProfiles.dll del CSOM. Este método simplemente necesita un array de strings con las direcciones de e-mail de los usuarios de Office 365 para los que se va a provisionar ODFB como podéis ver en el script que he creado al respecto: How to do a bulk creation of OneDrive For Business sites in Office 365

############################################################################################################################################

#Script that allows to asynchronously provision OneDrive For Business for a set of users

# Required Parameters:

#  -> $sCSOMPath: Path for the Client Side Object Model for SPO.

#  -> $sUserName: User Name to connect to the SharePoint Online Site Collection.

#  -> $sPassword: Password for the user.

#  -> $sSiteUrl: SharePoint Online Administration Url.

#  -> $ODFBUser: Office 365 user .

############################################################################################################################################

 

$host.Runspace.ThreadOptions = "ReuseThread"

 

#Definition of the function that allows to provision ODFB for a set of users

function Create-ODFBSite

{

    param ($sCSOMPath,$sSiteUrl,$sUserName,$sPassword,$sODFBUsers)

    try

    {    

        Write-Host "----------------------------------------------------------------------------"  -foregroundcolor Green

        Write-Host "Getting the User Profile Information for current user" -foregroundcolor Green

        Write-Host "----------------------------------------------------------------------------"  -foregroundcolor Green

                    

        #Adding the Client OM Assemblies

        $sCSOMRuntimePath=$sCSOMPath +  "\Microsoft.SharePoint.Client.Runtime.dll"  

        $sCSOMUserProfilesPath=$sCSOMPath +  "\Microsoft.SharePoint.Client.UserProfiles.dll"        

        $sCSOMPath=$sCSOMPath +  "\Microsoft.SharePoint.Client.dll"             

        Add-Type -Path $sCSOMPath         

        Add-Type -Path $sCSOMRuntimePath

        Add-Type -Path $sCSOMUserProfilesPath

 

        #SPO Client Object Model Context

        $spoCtx = New-Object Microsoft.SharePoint.Client.ClientContext($sSiteUrl) 

        $spoCredentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($sUserName, $sPassword)  

        $spoCtx.Credentials = $spoCredentials        

        $spoUserProfilesLoader=[Microsoft.SharePoint.Client.UserProfiles.ProfileLoader]::GetProfileLoader($spoCtx)     

        $spoUserProfilesLoader.CreatePersonalSiteEnqueueBulk($sODFBUsers)

        $spoUserProfilesLoader.Context.ExecuteQuery()

        $spoCtx.Dispose()

    }

    catch [System.Exception]

    {

        write-host -f red $_.Exception.ToString()   

    }    

}

 

#Required Parameters

$sSiteUrl = "https://<SPO_Site_Url>/" 

$sUserName = "<SPOUser>@<SPO_Domain>.onmicrosoft.com" 

$sPassword = Read-Host -Prompt "Enter your password: " -AsSecureString

$sCSOMPath="<CSOM_Path>"

$sODFBUsers="<SPOUser1>@<SPO_Domain>.onmicrosoft.com","<SPOUser2>@<SPO_Domain>.onmicrosoft.com"

 

Create-ODFBSite -sCSOMPath $sCSOMPath -sSiteUrl $sSiteUrl -sUserName $sUserName -sPassword $sPassword -sODFBUsers $sODFBUsers

Para verificar que los sitios de ODFB han sido provisionados os recomiendo el siguiente post de Thomas Balkeståhl: http://blog.blksthl.com/2014/08/08/office-365-guide-series-verify-provisioned-onedrives-using-powershell/