Skip to content

Instantly share code, notes, and snippets.

@darrenjrobinson darrenjrobinson/Export.ps1
Last active Nov 17, 2018

What would you like to do?
Microsoft Identity Manager SharePoint Online Powershell Management Agent Export Script. Supporting blog post can be located here
#SPO Admin URL
$site = ''
# Import the required DLL after installing the SPO SDK
Import-Module 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.UserProfiles.dll'
Import-Module 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll'
#Get the Client Context and Bind the Site Collection
$context = New-Object Microsoft.SharePoint.Client.ClientContext($site)
#Authentication Creds
$securestring = New-Object -TypeName System.Security.SecureString
$password.ToCharArray() | ForEach-Object {$securestring.AppendChar($_)}
$SPOcredentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $securestring )
$context.Credentials = $SPOcredentials
$people = New-Object Microsoft.SharePoint.Client.UserProfiles.PeopleManager($context)
$errorstatus = "success"
$errordetails = $null
$Identifier = $_.'[Identifier]'
$objectGuid = $_.'[DN]'
#Loop through changes and update parameters
foreach ($can in $_.'[ChangedAttributeNames]')
if ( $can -eq 'SPS-Department'){$SPSDepartment = $_.'SPS-Department'}
if ( $can -eq 'SPS-JobTitle'){$SPSJobTitle = $_.'SPS-JobTitle'}
if ( $can -eq 'SPS-Location'){$SPSLocation = $_.'SPS-Location'}
#Supported ChangeType is Replace
if ($_.'[ObjectModificationType]' -eq 'Replace')
$errorstatus = "success"
# Get the SPO User
# Get the user we're processing
$targetAccount = $_.AccountName
$myprofile = $people.GetPropertiesFor($targetAccount)
# Process our updates
if ($SPSDepartment) { $people.SetSingleValueProfileProperty($targetAccount, 'SPS-Department', $SPSDepartment) }
if ($SPSJobTitle) { $people.SetSingleValueProfileProperty($targetAccount, 'SPS-JobTitle', $SPSJobTitle) }
if ($SPSLocation) { $people.SetSingleValueProfileProperty($targetAccount, 'SPS-Location', $SPSLocation) }
# Commit the updates
#Return the result to the MA
$obj = @{}
if($errordetails){$obj.Add("[ErrorDetail]",$errordetails) }
#All done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.