Delete user property in SharePoint 2010 using PowerShell

In this article we will be seeing how to delete a user property in SharePoint 2010 using PowerShell.

Delete User Property in SharePoint 2010

We can delete a user property in SharePoint 2010 from Central Administration.

  • Go to Central Administration => Application Management => Manage Service Applications => User Profile Service Application.


  • Click on Manage User Properties


  • Click on the User property and then click on Delete in the ECB menu. You could see the user property will be deleted successfully.

Automation: Delete user property in SharePoint 2010 using PowerShell

Here we will be seeing how to delete a user property in SharePoint 2010 using PowerShell. Steps Involved:

  1. Create the input xml file which contains the inputs for deleting user property.

  2. Create ps1 file which contains the script for deleting user property.


DeleteUserProperty.xml

<?xml version="1.0" encoding="utf-8" ?> <DeleteUserProperty>   <SiteURL>http://serverName:8080/</SiteURL>   <Property Name="Sample1" ></Property>    <Property Name="Sample2" ></Property>    <Property Name="Sample3" ></Property>    <Property Name="Sample4" ></Property> </DeleteUserProperty>

DeleteUserProperty.ps1

#----------------Get the xml file----------------------------------------------------- ----------

  [xml]$xmlData=Get-Content "C:\Users\Desktop\ContentSources\DeletUserProperty.xml"

#----------------Create delete User Property ------------------------------------------ --- function DeleteUserProperty() {     $site = Get-SPSite $xmlData.DeletUserProperty.SiteURL $context = Get-SPServiceContext($site)       $upcm = New-Object Microsoft.Office.Server.UserProfiles.UserProfileConfigManager($context)          $cm = $upcm.ConnectionManager                        $pdtc = $upcm.GetPropertyDataTypes()       $ppm = $upcm.ProfilePropertyManager       $cpm = $ppm.GetCoreProperties()       $ptpm = $ppm.GetProfileTypeProperties([Microsoft.Office.Server.UserProfiles.ProfileType]::User)       $psm = [Microsoft.Office.Server.UserProfiles.ProfileSubTypeManager]::Get($context)       $ps = $psm.GetProfileSubtype([Microsoft.Office.Server.UserProfiles.ProfileSubtypeManager]::GetDefaultProfileName([Microsoft.Office.Server.UserProfiles.ProfileType]::User))       $pspm = $ps.Properties       $xmlData.DeletUserProperty.Property | ForEach-Object{

          $property = $pspm.GetPropertyByName($_.Name)                     if($property -ne $null)         {           Write-Host -f Magenta "Deleting" $_.Name "property ............."           $cpm.RemovePropertyByName($_.Name)                    Write-Host -f Green $_.Name "property is deleted successfully"         }         else         {           Write-Host -f Yellow $_.Name "property does not exists"         }     }   }

#----------------Calling the function---------------------------------------------

DeleteUserProperty

Run the Script:

  1. Go to Start.

  2. Click on All Programs.

  3. Click on Microsoft SharePoint 2010 Products and then click on SharePoint 2010 Management Shell.

  4. Run the C:\Users\Desktop\ContentSources\DeleteUserProperty.ps1