Office 365: How to query the User Information List in SPO using PowerShell!

This time I’m sharing a PowerShell script that allows to query the User Information List in a SharePoint Online (SPO) site using the Client Side Object Model (CSOM) and PowerShell. You can download the script from the following Url: How to query the user information list in a SPO site

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

# Script that allows to query the User Information List ina a SPO Site

# Required Parameters:

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

#  -> $sPassword: Password for the user.

#  -> $sSPOSiteUrl: SharePoint Online Site Url.

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

 

$host.Runspace.ThreadOptions = "ReuseThread"

 

#Definition of the function that allows to query the User Information List ina a SPO Site

function Query-UserInfoList

{

    param ($sSPOSiteUrl,$sUserName,$sPassword,$sCSOMPath)

    try

    {            

        Write-Host "----------------------------------------------------------------------------"  -ForegroundColor Green

        Write-Host "Querying SPO User Information List using CSOM" -ForegroundColor Green

        Write-Host "----------------------------------------------------------------------------"  -ForegroundColor Green

     

        #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        

 

        #SPO Client Object Model Context

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

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

        $spoCtx.Credentials = $spoCredentials 

        $spoWeb=$spoCtx.Web;

        $spoUserInformationList=$spoWeb.SiteUserInfoList

        $spoCamlQuery=New-Object Microsoft.SharePoint.Client.CamlQuery

        $spoCamlQuery.ViewXml=""

        $spoUsersCollection=$spoCtx.LoadQuery($spoUserInformationList.GetItems($spoCamlQuery))

        $spoCtx.ExecuteQuery()

        foreach($spoUser in $spoUsersCollection){

            Write-Host "    -> User ID:" $spoUser.Id " - User Title:" $spoUser["Title"] " - User E-Mail:" $spoUser["EMail"]             

            }   

        

        $spoCtx.Dispose()

       

    }

    catch [System.Exception]

    {

        Write-Host -ForegroundColor Red $_.Exception.ToString()   

    }    

}

 

#Required Parameters

$sSPOSiteUrl = "https://<SPOSite_Collection_Url>" 

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

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

$sPassword= ConvertTo-SecureString "<O365Password>" -AsPlainText -Force

$sCSOMPath="<CSOM_Path>"

 

Query-UserInfoList -sSPOSiteUrl $sSPOSiteUrl -sUserName $sUserName -sPassword $sPassword -sCSOMPath $sCSOMPath

Anuncios

Un pensamiento en “Office 365: How to query the User Information List in SPO using PowerShell!

  1. Pingback: SharePoint & Office 365: Resumen de posts (XIII)! | 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 )

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 )

Google+ photo

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

Conectando a %s