Last active
November 17, 2018 22:02
-
-
Save darrenjrobinson/bde7d7ad16011f68cb12 to your computer and use it in GitHub Desktop.
Microsoft Identity Manager SharePoint Online Powershell Management Agent Import 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, | |
$Credentials, | |
$OperationType, | |
[bool] $usepagedimport, | |
$pagesize | |
) | |
# SharePoint Online Tennat Name with -admin suffic | |
$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 | |
#Fetch the users in Site Collection | |
$users = $context.Web.SiteUsers | |
$context.Load($users) | |
$context.ExecuteQuery() | |
#Create an Object [People Manager] to retrieve profile information | |
$people = New-Object Microsoft.SharePoint.Client.UserProfiles.PeopleManager($context) | |
ForEach($user in $users) | |
{ | |
$userprofile = $people.GetPropertiesFor($user.LoginName) | |
$context.Load($userprofile) | |
$context.ExecuteQuery() | |
$profileattributes = $UserProfile.UserProfileProperties | Select-object | |
#Only process the object if they are a full user | |
if ($profileattributes.'msOnline-ObjectId' ) | |
{ | |
$obj = @{} | |
$obj.Add("msOnline-ObjectId",$profileattributes.'msOnline-ObjectId') | |
$obj.Add("objectClass", "user") | |
$obj.Add("AccountName", $profileattributes.AccountName) | |
$obj.Add("SPS-Department", $profileattributes.'SPS-Department') | |
$obj.Add("SPS-JobTitle", $profileattributes.'SPS-JobTitle') | |
$obj.Add("SPS-Location", $profileattributes.'SPS-Location') | |
$obj.Add("SPS-SipAddress", $profileattributes.'SPS-SipAddress') | |
$obj.Add("SPS-UserPrincipalName", $profileattributes.'SPS-UserPrincipalName') | |
$obj.Add("SID",$profileattributes.SID) | |
$obj.Add("FirstName", $profileattributes.FirstName) | |
$obj.Add("LastName", $profileattributes.LastName) | |
$obj.Add("PreferredName", $profileattributes.PreferredName) | |
$obj.Add("WorkPhone", $profileattributes.WorkPhone) | |
$obj.Add("Department", $profileattributes.Department) | |
$obj.Add("Title", $profileattributes.Title) | |
$obj.Add("Manager", $profileattributes.Manager) | |
$obj.Add("AboutMe", $profileattributes.AboutMe) | |
$obj.Add("PersonalSpace", $profileattributes.PersonalSpace) | |
$obj.Add("PictureURL", $profileattributes.PictureURL) | |
$obj.Add("SPS-PersonalSiteCapabilities", $profileattributes.'SPS-PersonalSiteCapabilities') #Integer in a String Attr | |
$obj.Add("SPS-DistinguishedName", $profileattributes.'SPS-DistinguishedName') | |
$obj.Add("SPS-SourceObjectDN", $profileattributes.'SPS-SourceObjectDN') | |
$obj.Add("WorkEmail", $profileattributes.WorkEmail) | |
$obj.Add("HomePhone", $profileattributes.HomePhone) | |
$obj.Add("Office", $profileattributes.Office) | |
$obj.Add("CellPhone", $profileattributes.CellPhone) | |
$obj.Add("SPS-UserType", $profileattributes.'SPS-UserType') #Integer in a String Attr | |
$obj.Add("SPS-HideFromAddressLists", $profileattributes.'SPS-HideFromAddressLists') #Boolean in a String Attr | |
$obj | |
} | |
} | |
#endregion |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment