Skip to content

Instantly share code, notes, and snippets.

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

Embed
What would you like to do?
Microsoft Identity Manager SharePoint Online Powershell Management Agent Export Script. Supporting blog post can be located here https://blog.darrenjrobinson.com/managing-sharepoint-online-spo-user-profiles-with-fimmim-2016-and-the-granfeldt-powershell-ma/
param
(
$username,
$password,
$ExportType
)
begin
{
#SPO Admin URL
$site = 'https://customertennant-admin.sharepoint.com/'
# Import the required DLL after installing the SPO SDK
# http://www.microsoft.com/en-us/download/details.aspx?id=42038
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)
}
process
{
$error.clear()
$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)
$context.Load($myprofile)
$context.ExecuteQuery()
# 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
$context.ExecuteQuery()
}
#Return the result to the MA
$obj = @{}
$obj.Add("[Identifier]",$Identifier)
$obj.Add("[ErrorName]","success")
if($errordetails){$obj.Add("[ErrorDetail]",$errordetails) }
$obj
}
end
{
#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.