Last active
November 17, 2018 22:03
-
-
Save darrenjrobinson/bbcb973edf211c7b351e to your computer and use it in GitHub Desktop.
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/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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