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