Quantcast
Channel: SharePoint 2010 - General Discussions and Questions forum
Viewing all articles
Browse latest Browse all 17574

How to sync department from active directory to sharepoint

$
0
0

Hi

 i want to sync department from active directory to sharepoint for 1 user.

user department need to update in sharepoint from active directory.

pls check and validate the following

----

function Sync-SPUser([string]$userName, [string]$Department) {

  Get-SPSite -Limit All | foreach {

    $web = $_.RootWeb

    if ($_.WebApplication.UseClaimsAuthentication) {

      $claim = New-SPClaimsPrincipal $userName -IdentityType WindowsSamAccountName

      $user = $web | Get-SPUser -Identity $claim -ErrorAction SilentlyContinue

    } else {

      $user = $web | Get-SPUser -Identity $userName -ErrorAction SilentlyContinue

    }

    if ($user -ne $null) {

      $web | Set-SPUser -Identity $user -SyncFromAD

     

      $list = $web.Lists["User Information List"]

      $query = New-Object Microsoft.SharePoint.SPQuery

      $query.Query = "$userName"

      foreach ($item in $list.GetItems($query)) {

        $item["Department"] = $Department

        $item.SystemUpdate()

      }

    }

    $web.Dispose()

    $_.Dispose()

  }

}

-----------------------------------------------------------------

save this as Sync-SPUser.ps1

 

Sync-SPUser "Redmond\a-vfram" "EDP Mgmtxc"

$webapp = Get-SPWebApplication "http://sharepoint/"

 


Subhash


Viewing all articles
Browse latest Browse all 17574

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>