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.
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("[email protected]");
foreach($userProfile in $upm)
{
$userProfile["PropertyName"].Value = "Test Value";
$userProfile.Commit()
}
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
}
[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()
}
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