Office 365: How to add a secondary administrator to ODFB using CSOM!

This time I’m sharing a new script that allows to add a secondary administrator to a user’s OneDrive For Business (ODFB) using Cliente Side Object Model (CSOM) for SharePoint Online (SPO). You can download the script from the following Url: How to add a secondary administrator to a user’s ODFB (CSOM Edition)

############################################################################################################################################
# Script that allows to set a secondary administrator for a specific user's ODFB.
# Required Parameters:
#  -> $sCSOMPath: CSOM Path.
#  -> $sUserName: User Name to connect to the SharePoint Admin Center.
#  -> $sPassword: User's password.
#  -> $sSPOAdminCenterUrl: SharePoint Admin Center Url.
#  -> $sSPOODFBHostUrl: SharePoint ODFB Host URL.
#  -> $sSPODFBRelativePath: ODFB Relative Path.
#  -> $sSecondaryODFBdmin: Login of the secondary administrator to be added to the user's OneDrive.
############################################################################################################################################

$host.Runspace.ThreadOptions = "ReuseThread"

#Definition of the function that sets a secondary administrator for an specific ODFB using CSOM
function Set-OneDriveFBSecondaryAdministrator_CSOM
{
    param ($sCSOMPath,$sUserName,$sPassword,$sSPOAdminCenterUrl,$sSPOODFBHostUrl,$sSPODFBRelativePath,$sSecondaryODFBAdmin)
    try
    {   
    
        #Adding the Client OM Assemblies        
        $sCSOMRuntimePath=$sCSOMPath +  "\Microsoft.SharePoint.Client.Runtime.dll"        
        $sCSOMPath=$sCSOMPath +  "\Microsoft.SharePoint.Client.dll"             
        Add-Type -Path $sCSOMPath         
        Add-Type -Path $sCSOMRuntimePath       

        $sODFBSite=$sSPOODFBHostUrl + $sSPODFBRelativePath 

        #SPO Client Object Model Context
        $spoCtx = New-Object Microsoft.SharePoint.Client.ClientContext($sODFBSite)
        $spoCredentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($sUserName, $sPassword)  
        $spoCtx.Credentials = $spoCredentials     
         
        Write-Host "----------------------------------------------------------------------------------"  -ForegroundColor Green
        Write-Host "Setting secondary ODFB Admin for $sUserName ODFB" -ForegroundColor Green
        Write-Host "----------------------------------------------------------------------------------"  -ForegroundColor Green
        
        $spoUser=$spoCtx.Web.EnsureUser($sSecondaryODFBAdmin)
        $spoUser.IsSiteAdmin=$true
        $spoUser.Update()
        $spoCtx.Load($spoUser)
        $spoCtx.ExecuteQuery()
        
        Write-Host "----------------------------------------------------------------------------------"  -ForegroundColor Green
        Write-Host "Secondary ODFB Admin successfully added to $sUserName ODFB" -ForegroundColor Green
        Write-Host "----------------------------------------------------------------------------------"  -ForegroundColor Green
        
        $spoCtx.Dispose()

    }
    catch [System.Exception]
    {
        Write-Host -ForegroundColor Red $_.Exception.ToString()   
    }    
}

$sCSOMPath="<SPO_Path>"

$sUserName="<O365User>@<O365Domain>.onmicrosoft.com"

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

$sSPOAdminCenterUrl="https://<O365Domain>-admin.sharepoint.com/"

$sSPOODFBHostUrl="https://<O365Domain>-my.sharepoint.com/personal/"

$sSPODFBRelativePath="<O365User>_<O365Domain>_onmicrosoft_com"

$sSecondaryODFBAdmin="<O365User>@<O365Domain>.onmicrosoft.com"


Set-OneDriveFBSecondaryAdministrator_CSOM -sCSOMPath $sCSOMPath -sUserName $sUserName -sPassword $sPassword -sSPOAdminCenterUrl $sSPOAdminCenterUrl -sSPOODFBHostUrl $sSPOODFBHostUrl -sSPODFBRelativePath $sSPODFBRelativePath -sSecondaryODFBAdmin $sSecondaryODFBAdmin
Anuncios

Office 365: Como añadir un administrador secundario en ODFB con CSOM!

Después de la serie de artículos sobre como añadir un administrador secundario en OneDrive For Business (ODFB), en esta ocasión os comparto una opción adicional que permite agregar dicho administrador usando la API de cliente de SharePoint Online (SPO). Pero antes os recuerdo los posts previos de la serie:

El script, que podéis descargaros de la PowerShell Script TechNet Gallery () es el siguiente: How to add a secondary administrator to a user’s ODFB (CSOM Edition)

############################################################################################################################################
# Script that allows to set a secondary administrator for a specific user's ODFB.
# Required Parameters:
#  -> $sCSOMPath: CSOM Path.
#  -> $sUserName: User Name to connect to the SharePoint Admin Center.
#  -> $sPassword: User's password.
#  -> $sSPOAdminCenterUrl: SharePoint Admin Center Url.
#  -> $sSPOODFBHostUrl: SharePoint ODFB Host URL.
#  -> $sSPODFBRelativePath: ODFB Relative Path.
#  -> $sSecondaryODFBdmin: Login of the secondary administrator to be added to the user's OneDrive.
############################################################################################################################################

$host.Runspace.ThreadOptions = "ReuseThread"

#Definition of the function that sets a secondary administrator for an specific ODFB using CSOM
function Set-OneDriveFBSecondaryAdministrator_CSOM
{
    param ($sCSOMPath,$sUserName,$sPassword,$sSPOAdminCenterUrl,$sSPOODFBHostUrl,$sSPODFBRelativePath,$sSecondaryODFBAdmin)
    try
    {   
    
        #Adding the Client OM Assemblies        
        $sCSOMRuntimePath=$sCSOMPath +  "\Microsoft.SharePoint.Client.Runtime.dll"        
        $sCSOMPath=$sCSOMPath +  "\Microsoft.SharePoint.Client.dll"             
        Add-Type -Path $sCSOMPath         
        Add-Type -Path $sCSOMRuntimePath       

        $sODFBSite=$sSPOODFBHostUrl + $sSPODFBRelativePath 

        #SPO Client Object Model Context
        $spoCtx = New-Object Microsoft.SharePoint.Client.ClientContext($sODFBSite)
        $spoCredentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($sUserName, $sPassword)  
        $spoCtx.Credentials = $spoCredentials     
         
        Write-Host "----------------------------------------------------------------------------------"  -ForegroundColor Green
        Write-Host "Setting secondary ODFB Admin for $sUserName ODFB" -ForegroundColor Green
        Write-Host "----------------------------------------------------------------------------------"  -ForegroundColor Green
        
        $spoUser=$spoCtx.Web.EnsureUser($sSecondaryODFBAdmin)
        $spoUser.IsSiteAdmin=$true
        $spoUser.Update()
        $spoCtx.Load($spoUser)
        $spoCtx.ExecuteQuery()
        
        Write-Host "----------------------------------------------------------------------------------"  -ForegroundColor Green
        Write-Host "Secondary ODFB Admin successfully added to $sUserName ODFB" -ForegroundColor Green
        Write-Host "----------------------------------------------------------------------------------"  -ForegroundColor Green
        
        $spoCtx.Dispose()

    }
    catch [System.Exception]
    {
        Write-Host -ForegroundColor Red $_.Exception.ToString()   
    }    
}

$sCSOMPath="<SPO_Path>"

$sUserName="<O365User>@<O365Domain>.onmicrosoft.com"

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

$sSPOAdminCenterUrl="https://<O365Domain>-admin.sharepoint.com/"

$sSPOODFBHostUrl="https://<O365Domain>-my.sharepoint.com/personal/"

$sSPODFBRelativePath="<O365User>_<O365Domain>_onmicrosoft_com"

$sSecondaryODFBAdmin="<O365User>@<O365Domain>.onmicrosoft.com"


Set-OneDriveFBSecondaryAdministrator_CSOM -sCSOMPath $sCSOMPath -sUserName $sUserName -sPassword $sPassword -sSPOAdminCenterUrl $sSPOAdminCenterUrl -sSPOODFBHostUrl $sSPOODFBHostUrl -sSPODFBRelativePath $sSPODFBRelativePath -sSecondaryODFBAdmin $sSecondaryODFBAdmin

How to keep up with changes in Office 365!

Have you heard about the virtual Collab365 Global Conference 2017 that’s streaming online November 1st – 2nd?

Join me and 120 other speakers from around the world who will be bringing you the very latest content around SharePoint, Office 365, Flow, PowerApps, Azure, OneDrive for Business and of course the increasingly popular Microsoft Teams. The event is produced by the Collab365 Community and is entirely free to attend.

Places are limited to 5000 so be quick and register now.

During the conference I’d love you to watch my session which is called : ‘How to keep up with changes in Office 365 ‘

Office 365 enhancements, new features and functionalities are always expected to be released to the public following a well-defined process so every Office 365 customer should know when the new goodies are expected to appear in his tenant…however, is a well-known fact that the release process doesn’t work as it should and Office 365 customers get unexpected surprises in their tenants. In this session, we will talk about this release process and about the communication tools we have to keep up with changes in Office 365.

If you join me, you will learn:

  • Tools & resources to keep up with changes in Office 365
  • Office 365 Change Management Toolbox
  • Tips, best practices and roadmap about changes in Office 365

Topic(s):

  • Office365

Audience :

  • IT Manager

Time (in UTC) :

  • Thursday, November 2 2017 7:00 PM

How to attend :

  1. Register here.
  2. At the time listed above go here to watch my session. (you can also add me to your own personal planner from the agenda.
  3. Be ready to take notes!