SharePoint Online: How to get User Profile Information through PowerShell!

This time I’m sharing a new PowerShell Script that allows to get User Profile Information by using the Client Side Object Model for SharePoint Online. You can download the script from the following URL:

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

#Script that allows to get user profile information

# 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.

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

 

$host.Runspace.ThreadOptions = "ReuseThread"

 

#Definition of the function that gets user profile information

function Get-UserProfileInfo

{

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

    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)

        $spoProfile=$spoUserProfilesLoader.GetUserProfile()

        $spoCtx.Load($spoProfile)

        $spoCtx.ExecuteQuery()

        $spoProfile

        $spoCtx.Dispose()

    }

    catch [System.Exception]

    {

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

    }    

}

 

#Required Parameters

$sSiteUrl = "https://nuberosnet-admin.sharepoint.com/" 

$sUserName = "jcgonzalez@nuberosnet.onmicrosoft.com" 

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

$sCSOMPath="E:3 Docs\19 MVP Cluster1 Marketing1 Eventos1 Curso Office 3651 Materiales4 Demos1 PS\DLLs"

 

 

Get-UserProfileInfo -sCSOMPath $sCSOMPath -sSiteUrl $sSiteUrl -sUserName $sUserName -sPassword $sPassword

And this is the result you get once you execute the script in PowerShell ISE: How to get User Profile Information in SharePoint Online using PowerShell!

image

SharePoint Online: Como obtener la información del perfil de usuario con PowerShell!

En esta ocasión os dejo un nuevo script PowerShell que haciendo uso del Modelo de Objetos en Cliente para SharePoint Online permite leer las propiedades del Perfil de Usuario. Podéis descargaros el script desde el siguiente enlace:How to get User Profile Information in SharePoint Online using PowerShell!

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

#Script that allows to get user profile information

# 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.

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

 

$host.Runspace.ThreadOptions = "ReuseThread"

 

#Definition of the function that gets user profile information

function Get-UserProfileInfo

{

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

    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)

        $spoProfile=$spoUserProfilesLoader.GetUserProfile()

        $spoCtx.Load($spoProfile)

        $spoCtx.ExecuteQuery()

        $spoProfile

        $spoCtx.Dispose()

    }

    catch [System.Exception]

    {

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

    }    

}

 

#Required Parameters

$sSiteUrl = "https://nuberosnet-admin.sharepoint.com/" 

$sUserName = "jcgonzalez@nuberosnet.onmicrosoft.com" 

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

$sCSOMPath="E:3 Docs\19 MVP Cluster1 Marketing1 Eventos1 Curso Office 3651 Materiales4 Demos1 PS\DLLs"

 

 

Get-UserProfileInfo -sCSOMPath $sCSOMPath -sSiteUrl $sSiteUrl -sUserName $sUserName -sPassword $sPassword

Y la correspondiente salida por pantalla es la siguiente:

image