12

We have a bool: User profile property.

Is there a way to set the value of this field to 'false' for all users?

The user profile property exists only in the SharePoint and not in AD.

12

You can iterate through all user profiles and update them. The PowerShell script can look like this:

[void][reflection.assembly]::Loadwithpartialname("Microsoft.Office.Server"); 
Add-PSSnapin Microsoft.SharePoint.PowerShell

$site=Get-SPSite "https://yourSitecCollection"
$serviceContext = Get-SPServiceContext $site;            

$upm = new-object Microsoft.Office.Server.UserProfiles.UserProfileManager($serviceContext);            
$userProfile = $upm.GetUserProfile("myarlett@company.com");

foreach($userProfile in $upm)
{
  $userProfile["PropertyName"].Value = "Test Value";   
  $userProfile.Commit()
}
1

You can try something like this,

Get-ADUser -Filter * -SearchBase "ou=TestOU,dc=domainController01,dc=com" | Set-ADUser -customProperty $true

OR

# Get all users in the SomeOU.
$AllUsers = Get-ADUser -Filter * -SearchBase "OU=ChangeMeOU,OU=UserAccounts,DC=DomainController01,DC=COM"
# Iterate the users and update the department and title attributes in AD.
foreach($oUser in $AllUsers)
{
    # Update properties.
    $oUser.department = "Finance"
    $oUser.title = "Analyst 1"   
    # Update the user data in AD using the Instance parameter of Set-ADUser.

    oUser.CustomProperty = "WhateverYouWantHere"
    Set-ADUser -Instance $oUser
}
  • This will only change the AD User but not the user profile in SharePoint. – Stefan Bauer Apr 9 '14 at 11:38
  • true, Once user changed AD, they can run a synchronize in Central Admin to see the changes. – Muhammad Raja Apr 9 '14 at 12:01
  • Well if the property exists in the Profile and Active Directory and if they are mapped then it might probably work yes. ;) – Stefan Bauer Apr 9 '14 at 21:20
  • 1
    The user property exists only in the SharePoint and not in AD. – variable Apr 10 '14 at 4:33
1
[void][reflection.assembly]::Loadwithpartialname("Microsoft.Office.Server"); 
Add-PSSnapin Microsoft.SharePoint.PowerShell

$site=Get-SPSite "http://site:8080"
$serviceContext = Get-SPServiceContext $site;            

$upm = new-object Microsoft.Office.Server.UserProfiles.UserProfileManager($serviceContext);    
$profiles = $upm.GetEnumerator()        
foreach($userProfile in $profiles)
{
    write-host $userProfile["AccountName"]
    write-host $($userProfile["AboutMe"])
    write-host $($userProfile["Matricule"])
    write-host "Telephone :" $($userProfile["HomePhone"])
    $userProfile["AboutMe"].Value = "Matricule: "+ $userProfile["Matricule"].Value+",  Tel: "+     $userProfile["HomePhone"].Value;   
    $userProfile.Commit()
}

This work well !

  • the code of "Anton Khritonenkov" miss $profiles = $upm.GetEnumerator() before foreach – Anis ELTAIEF Dec 31 '15 at 18:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.