This is the script im using to delete the sharepoint userprofile property using powershell.

#Load Sharepoint SnapIn
if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null)
    Add-PSSnapin Microsoft.SharePoint.PowerShell

# Variables
$path = "path of the xml file"  
# Reading XML File 
write-host -f yellow "Reading XML File Path=" $path
[xml]$xmldata= Get-Content $path
$connectionName = $xmldata.UserProfileProperties.ADName

# start Script

$site = Get-SPSite $xmldata.UserProfileProperties.SPSite
$serviceContext = Get-SPServiceContext $site 
$userProfileConfigManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileConfigManager($serviceContext)
$connectionManager = $userProfileConfigManager.ConnectionManager 
$connection = $connectionManager[$connectionName]
$propertyMapCollection = $connection.PropertyMapping
$profilePropertyManager = $userProfileConfigManager.ProfilePropertyManager
$corePropertyManager = $profilePropertyManager.GetCoreProperties()
$secMan = $userProfileConfigManager.GetPropertiesWithSection()
$profileTypePropertyManager = $profilePropertyManager.GetProfileTypeProperties([Microsoft.Office.Server.UserProfiles.ProfileType]::User)
$profileSubTypeManager = [Microsoft.Office.Server.UserProfiles.ProfileSubTypeManager]::Get($serviceContext)
$defaultSubType = [Microsoft.Office.Server.UserProfiles.ProfileSubtypeManager]::GetDefaultProfileName([Microsoft.Office.Server.UserProfiles.ProfileType]::User)
$profileSubType = $profileSubTypeManager.GetProfileSubtype($defaultSubType)
$profileSubTypePropertyManager = $profileSubType.Properties

#Remove the manager user property Active Directory mapping
    if($connection -ne $null)
        $pm = $connection.PropertyMapping["manager"];
        if($pm -ne $null)
            Write-Host -f Yellow "AD Property manager is deleted"
            Write-Host -f Yellow "AD Property manager is not mapped to any user property"
        Write-Host -f Yellow $connectionName " does not exists"

But when I run this code its giving the following error.

Cannot index into a null array. At C:\Users\hearttest\Desktop\Roy -
Scripts\sharepointuserpropertysetupshellscript\SharepointUserPropertySetupScript.ps1:51 char:13 + $pm = $connection.PropertyMapping["manager"]; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : NullArray

Im really new to this powershell scripts please help me out on this asap.

  • Your code cannot work as you're trying to do $connection.PropertyMapping. But $connection is the ConnectionManagerand doesn't have property mappings.
    – Dennis G
    Commented Feb 21, 2014 at 17:29

1 Answer 1


Your code can't work, too many errors to list.

The following code would delete the user profile property "Company":

Add-Type -Path "c:\program files\common files\microsoft shared\web server extensions\15\isapi\microsoft.office.server.dll"
$site = Get-SPSite -Limit 1 #get site for context
$ctx = Get-SPServiceContext($site) #get context
$cfgManager= new-object Microsoft.Office.Server.UserProfiles.UserProfileConfigManager($ctx) #get the profile config manager
$propManager= $CfgManager.ProfilePropertyManager #get the property manager
$properties = $propMgr.GetCoreProperties()  # load all properties to variable
  • Hello, can you tell me where exactly is the user profile property values stored? Is it against some list or waht?
    – variable
    Commented Mar 24, 2014 at 4:20
  • The database of course. Something you shouldn't touch ;-)
    – Dennis G
    Commented Mar 24, 2014 at 19:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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