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
}
4
  • This will only change the AD User but not the user profile in SharePoint. Apr 9 '14 at 11:38
  • true, Once user changed AD, they can run a synchronize in Central Admin to see the changes. 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. ;) 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 !

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

You can directly update the profile properties and if its for all users then you can loop through all web.users

$web=get-spweb -identity http://

$user=$web.EnsureUser("")

$user | fl -- this will show the user id and pass that id to below script in GetitembyID method

$web=get-spweb -identity http://

$list=$web.lists["user information list"]

$item=$list.GetItemById(6007)

$item["JobTitle"]=""

$item["Department"]=""

$item.Update()

$list.Update()

$web.Update()

Refer:-https://www.sharepointcollabs.com/2021/06/updating-sharepoint-userprofile.html

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.