Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2016
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.55 KB | None | 0 0
  1. param(
  2. [ValidateNotNull()]
  3. [System.Collections.ObjectModel.KeyedCollection [string,Microsoft.MetadirectoryServices.ConfigParameter]] $ConfigParameters,
  4. [Microsoft.MetadirectoryServices.Schema]
  5. [ValidateNotNull()]
  6. $Schema,
  7. [Microsoft.MetadirectoryServices.OpenImportConnectionRunStep]
  8. $OpenImportConnectionRunStep,
  9. [Microsoft.MetadirectoryServices.ImportRunStep]
  10. $GetImportEntriesRunStep,
  11. [System.Management.Automation.PSCredential]
  12. $PSCredential
  13. )
  14. Set-StrictMode -Version 3.0
  15. Import-Module (Join-Path -Path ([Microsoft.MetadirectoryServices.MAUtils]::MAFolder) -ChildPath 'FIMPowerShellConnectorModule.psm1') -Verbose:$false
  16. Import-Module 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.UserProfiles.dll'
  17. Import-Module 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll'
  18.  
  19. foreach ($ConfigParameter in $ConfigParameters)
  20. {
  21. if ($ConfigParameter.Name -eq 'Server'){$Server = $ConfigParameter.Value.ToString()}
  22. if ($ConfigParameter.Name -eq 'Domain'){$Domain = $ConfigParameter.Value.ToString()}
  23. }
  24.  
  25. $importResults = New-FIMGetImportEntriesResults
  26. $csEntries = New-FIMCSEntryChanges
  27.  
  28. $username = $PSCredential.UserName
  29. $SecurePassword = $PSCredential.Password
  30.  
  31. # connect/authenticate to SharePoint Online and get ClientContext object..
  32. $clientContext = New-Object Microsoft.SharePoint.Client.ClientContext($Server)
  33. $credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $securePassword)
  34. $clientContext.Credentials = $credentials
  35.  
  36. #Fetch the users in Site Collection
  37. $users = $clientContext.Web.SiteUsers
  38. $clientContext.Load($users)
  39. $clientContext.ExecuteQuery()
  40.  
  41. #Create an Object [People Manager] to retrieve profile information
  42. $people = New-Object Microsoft.SharePoint.Client.UserProfiles.PeopleManager($clientContext)
  43.  
  44. ForEach($user in $users)
  45. {
  46. $userprofile = $people.GetPropertiesFor($user.LoginName)
  47. $clientContext.Load($userprofile)
  48. $clientContext.ExecuteQuery()
  49.  
  50. $profileattributes = $UserProfile.UserProfileProperties | Select-object
  51.  
  52. #Only process the object if they are a full user
  53. if ($profileattributes.'msOnline-ObjectId')
  54. {
  55. $csEntry = New-FIMCSEntryChange -ObjectType 'user' -ModificationType Add
  56. $csEntry.AnchorAttributes.Add([Microsoft.MetadirectoryServices.AnchorAttribute]::Create('SPS-UserPrincipalName', $profileattributes.'SPS-UserPrincipalName'))
  57. $csEntry.DN = $profileattributes.'SPS-UserPrincipalName'
  58. $csEntry.AttributeChanges.Add([Microsoft.MetadirectoryServices.AttributeChange]::CreateAttributeAdd('AboutMe', $profileattributes.AboutMe))
  59. $csEntry.AttributeChanges.Add([Microsoft.MetadirectoryServices.AttributeChange]::CreateAttributeAdd('AccountName', $profileattributes.AccountName))
  60. $csEntry.AttributeChanges.Add([Microsoft.MetadirectoryServices.AttributeChange]::CreateAttributeAdd('CellPhone', $profileattributes.CellPhone))
  61. $csEntry.AttributeChanges.Add([Microsoft.MetadirectoryServices.AttributeChange]::CreateAttributeAdd('Department', $profileattributes.Department))
  62. $csEntry.AttributeChanges.Add([Microsoft.MetadirectoryServices.AttributeChange]::CreateAttributeAdd('FirstName', $profileattributes.FirstName))
  63. $csEntry.AttributeChanges.Add([Microsoft.MetadirectoryServices.AttributeChange]::CreateAttributeAdd('HomePhone', $profileattributes.HomePhone))
  64. $csEntry.AttributeChanges.Add([Microsoft.MetadirectoryServices.AttributeChange]::CreateAttributeAdd('LastName', $profileattributes.LastName))
  65. $csEntry.AttributeChanges.Add([Microsoft.MetadirectoryServices.AttributeChange]::CreateAttributeAdd('Manager', $profileattributes.Manager))
  66. $csEntry.AttributeChanges.Add([Microsoft.MetadirectoryServices.AttributeChange]::CreateAttributeAdd('Office', $profileattributes.Office))
  67. $csEntry.AttributeChanges.Add([Microsoft.MetadirectoryServices.AttributeChange]::CreateAttributeAdd('PersonalSpace', $profileattributes.PersonalSpace))
  68. $csEntry.AttributeChanges.Add([Microsoft.MetadirectoryServices.AttributeChange]::CreateAttributeAdd('PictureURL', $profileattributes.PictureURL))
  69. $csEntry.AttributeChanges.Add([Microsoft.MetadirectoryServices.AttributeChange]::CreateAttributeAdd('PreferredName', $profileattributes.PreferredName))
  70. $csEntry.AttributeChanges.Add([Microsoft.MetadirectoryServices.AttributeChange]::CreateAttributeAdd('SID',$profileattributes.SID))
  71. $csEntry.AttributeChanges.Add([Microsoft.MetadirectoryServices.AttributeChange]::CreateAttributeAdd('SPS-Department', $profileattributes.'SPS-Department'))
  72. $csEntry.AttributeChanges.Add([Microsoft.MetadirectoryServices.AttributeChange]::CreateAttributeAdd('SPS-JobTitle', $profileattributes.'SPS-JobTitle'))
  73. $csEntry.AttributeChanges.Add([Microsoft.MetadirectoryServices.AttributeChange]::CreateAttributeAdd('SPS-Location', $profileattributes.'SPS-Location'))
  74. $csEntry.AttributeChanges.Add([Microsoft.MetadirectoryServices.AttributeChange]::CreateAttributeAdd('Title', $profileattributes.Title))
  75. $csEntry.AttributeChanges.Add([Microsoft.MetadirectoryServices.AttributeChange]::CreateAttributeAdd('WorkEmail', $profileattributes.WorkEmail))
  76. $csEntry.AttributeChanges.Add([Microsoft.MetadirectoryServices.AttributeChange]::CreateAttributeAdd('WorkPhone', $profileattributes.WorkPhone))
  77. $csEntries.Add($csEntry)
  78. }
  79. }
  80.  
  81. $importResults.MoreToImport = $false
  82. $importResults.CSEntries = $csEntries
  83.  
  84. Write-Output $importResults
  85.  
  86. $count=$users.Count
  87.  
  88. Write-Error "User Count is: $count"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement