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

3 pensamientos en “Office 365: How to add a secondary administrator to ODFB using CSOM!

  1. Buenas, se que mi pregunta no tiene que ver específicamente con este tema pero quisiera aprovechar para ver si alguien pudiese ayudarme con una duda que tengo. Necesito saber si en SharePoint online es posible crear reportes Power View y de ser posible como podría hacerlo ya que no me sale el tipo de contenido “Report Data Source”

  2. Pingback: SharePoint & Office 365: Resumen de posts (XXV)! | Pasión por la tecnología...

  3. Pingback: SharePoint & Office 365: Compilation of blog posts (XI)! | Pasión por la tecnología...

Responder

Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Cerrar sesión /  Cambiar )

Google+ photo

Estás comentando usando tu cuenta de Google+. Cerrar sesión /  Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión /  Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión /  Cambiar )

w

Conectando a %s