Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2016
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.63 KB | None | 0 0
  1. [CmdletBinding()]
  2. param
  3. (
  4. [ValidateNotNull()]
  5. [System.Collections.ObjectModel.KeyedCollection [string,Microsoft.MetadirectoryServices.ConfigParameter]] $ConfigParameters,
  6.  
  7. [System.Management.Automation.PSCredential] $PSCredential,
  8.  
  9. [System.Collections.Generic.IList[Microsoft.MetaDirectoryServices.CSEntryChange]] $CSEntries,
  10.  
  11. [Microsoft.MetadirectoryServices.OpenExportConnectionRunStep] $OpenExportConnectionRunStep,
  12.  
  13. [Microsoft.MetadirectoryServices.Schema] $Schema
  14. )
  15.  
  16. Set-StrictMode -Version 3.0
  17.  
  18. Import-Module (Join-Path -Path ([Microsoft.MetadirectoryServices.MAUtils]::MAFolder) -ChildPath 'FIMPowerShellConnectorModule.psm1') -Verbose:$false
  19. Import-Module 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.UserProfiles.dll'
  20. Import-Module 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll'
  21.  
  22. foreach ($ConfigParameter in $ConfigParameters)
  23. {
  24. if ($ConfigParameter.Name -eq 'Server'){$Server = $ConfigParameter.Value.ToString()}
  25. if ($ConfigParameter.Name -eq 'Domain'){$Domain = $ConfigParameter.Value.ToString()}
  26. }
  27.  
  28. $exportResults = New-Object Microsoft.MetadirectoryServices.PutExportEntriesResults
  29.  
  30. $username = $PSCredential.UserName
  31. $SecurePassword = $PSCredential.Password
  32.  
  33. # connect/authenticate to SharePoint Online and get ClientContext object..
  34. $clientContext = New-Object Microsoft.SharePoint.Client.ClientContext($Server)
  35. $credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $securePassword)
  36. $clientContext.Credentials = $credentials
  37.  
  38. $people = New-Object Microsoft.SharePoint.Client.UserProfiles.PeopleManager($clientContext)
  39.  
  40. foreach($CSEntry in $CSEntries)
  41. {
  42. switch ($CSEntry.ObjectType)
  43. {
  44. 'user'
  45. {
  46. $guid = $CSEntry.Identifier
  47. switch ($CSEntry.ObjectModificationType)
  48. {
  49. 'Add'
  50. {
  51. }
  52. 'Delete'
  53. {
  54. }
  55. 'Replace'
  56. {
  57. foreach ($ChangedAttribute in $CSEntry.ChangedAttributeNames)
  58. {
  59. if ($ChangedAttribute -eq 'AboutMe'){$AboutMe = $CSEntry.AttributeChanges['AboutMe'].ValueChanges[0].Value.ToString()}
  60. if ($ChangedAttribute -eq 'CellPhone'){$CellPhone = $CSEntry.AttributeChanges['CellPhone'].ValueChanges[0].Value.ToString()}
  61. if ($ChangedAttribute -eq 'Department'){$Department = $CSEntry.AttributeChanges['Department'].ValueChanges[0].Value.ToString()}
  62. if ($ChangedAttribute -eq 'FirstName'){$FirstName = $CSEntry.AttributeChanges['FirstName'].ValueChanges[0].Value.ToString()}
  63. if ($ChangedAttribute -eq 'HomePhone'){$HomePhone = $CSEntry.AttributeChanges['HomePhone'].ValueChanges[0].Value.ToString()}
  64. if ($ChangedAttribute -eq 'LastName'){$LastName = $CSEntry.AttributeChanges['LastName'].ValueChanges[0].Value.ToString()}
  65. if ($ChangedAttribute -eq 'Manager'){$Manager = $CSEntry.AttributeChanges['Manager'].ValueChanges[0].Value.ToString()}
  66. if ($ChangedAttribute -eq 'Office'){$Office = $CSEntry.AttributeChanges['Office'].ValueChanges[0].Value.ToString()}
  67. if ($ChangedAttribute -eq 'PersonalSpace'){$PersonalSpace = $CSEntry.AttributeChanges['PersonalSpace'].ValueChanges[0].Value.ToString()}
  68. if ($ChangedAttribute -eq 'PictureURL'){$PictureURL = $CSEntry.AttributeChanges['PictureURL'].ValueChanges[0].Value.ToString()}
  69. if ($ChangedAttribute -eq 'PreferredName'){$PreferredName = $CSEntry.AttributeChanges['PreferredName'].ValueChanges[0].Value.ToString()}
  70. if ($ChangedAttribute -eq 'SPS-Department'){$SPSDepartment = $CSEntry.AttributeChanges['SPS-Department'].ValueChanges[0].Value.ToString()}
  71. if ($ChangedAttribute -eq 'SPS-JobTitle'){$SPSJobTitle = $CSEntry.AttributeChanges['SPS-JobTitle'].ValueChanges[0].Value.ToString()}
  72. if ($ChangedAttribute -eq 'SPS-Location'){$SPSLocation = $CSEntry.AttributeChanges['SPS-Location'].ValueChanges[0].Value.ToString()}
  73. if ($ChangedAttribute -eq 'SPS-UserPrincipalName'){$SPSUserPrincipalName = $CSEntry.AttributeChanges['SPS-UserPrincipalName'].ValueChanges[0].Value.ToString()}
  74. if ($ChangedAttribute -eq 'Title'){$Title = $CSEntry.AttributeChanges['Title'].ValueChanges[0].Value.ToString()}
  75. if ($ChangedAttribute -eq 'WorkEmail'){$WorkEmail = $CSEntry.AttributeChanges['WorkEmail'].ValueChanges[0].Value.ToString()}
  76. if ($ChangedAttribute -eq 'WorkPhone'){$WorkPhone = $CSEntry.AttributeChanges['WorkPhone'].ValueChanges[0].Value.ToString()}
  77. }
  78. $SPSAccountName = $CSEntry.AttributeChanges['AccountName'].ValueChanges[0].Value.ToString()
  79. $csentryChangeResult = [Microsoft.MetadirectoryServices.CSEntryChangeResult]::Create($guid, $null, [Microsoft.MetadirectoryServices.MAExportError]::Success)
  80.  
  81. $targetAccount = $SPSAccountName
  82. $myprofile = $people.GetPropertiesFor($targetAccount)
  83. $clientContext.Load($myprofile)
  84. $clientContext.ExecuteQuery()
  85.  
  86. # Process our updates
  87. if ($AboutMe) {$people.SetSingleValueProfileProperty($targetAccount, 'AboutMe', $AboutMe)}
  88. if ($AccountName) {$people.SetSingleValueProfileProperty($targetAccount, 'AccountName', $AccountName)}
  89. if ($CellPhone) {$people.SetSingleValueProfileProperty($targetAccount, 'CellPhone', $CellPhone)}
  90. if ($Department) {$people.SetSingleValueProfileProperty($targetAccount, 'Department', $Department)}
  91. if ($FirstName) {$people.SetSingleValueProfileProperty($targetAccount, 'FirstName', $FirstName)}
  92. if ($HomePhone) {$people.SetSingleValueProfileProperty($targetAccount, 'HomePhone', $HomePhone)}
  93. if ($LastName) {$people.SetSingleValueProfileProperty($targetAccount, 'LastName', $LastName)}
  94. if ($Manager) {$people.SetSingleValueProfileProperty($targetAccount, 'Manager', $Manager)}
  95. if ($Office) {$people.SetSingleValueProfileProperty($targetAccount, 'Office', $Office)}
  96. if ($PersonalSpace) {$people.SetSingleValueProfileProperty($targetAccount, 'PersonalSpace', $PersonalSpace)}
  97. if ($PictureURL) {$people.SetSingleValueProfileProperty($targetAccount, 'PictureURL', $PictureURL)}
  98. if ($PreferredName) {$people.SetSingleValueProfileProperty($targetAccount, 'PreferredName', $PreferredName)}
  99. if ($SPSDepartment) {$people.SetSingleValueProfileProperty($targetAccount, 'SPS-Department', $SPSDepartment)}
  100. if ($SPSJobTitle) {$people.SetSingleValueProfileProperty($targetAccount, 'SPS-JobTitle', $SPSJobTitle)}
  101. if ($SPSLocation) {$people.SetSingleValueProfileProperty($targetAccount, 'SPS-Location', $SPSLocation)}
  102. if ($SPSUserPrincipalName) {$people.SetSingleValueProfileProperty($targetAccount, 'SPS-UserPrincipalName', $SPSUserPrincipalName)}
  103. if ($Title) {$people.SetSingleValueProfileProperty($targetAccount, 'Title', $Title)}
  104. if ($WorkEmail) {$people.SetSingleValueProfileProperty($targetAccount, 'WorkEmail', $WorkEmail)}
  105. if ($WorkPhone) {$people.SetSingleValueProfileProperty($targetAccount, 'WorkPhone', $WorkPhone)}
  106.  
  107. $clientContext.ExecuteQuery()
  108. $exportResults.CSEntryChangeResults.Add($csentryChangeResult)
  109.  
  110. }
  111. 'Update'
  112. {
  113. }
  114. default
  115. {
  116. $csentryChangeResult = [Microsoft.MetadirectoryServices.CSEntryChangeResult]::Create($guid, $null, [Microsoft.MetadirectoryServices.MAExportError]::Success)
  117. $exportResults.CSEntryChangeResults.Add($csentryChangeResult)
  118. }
  119. }
  120. }
  121. }
  122. }
  123.  
  124. Write-Output $exportResults
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement