Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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)
        {
            $pm.Delete();
            Write-Host -f Yellow "AD Property manager is deleted"
        }
        else
        {
            Write-Host -f Yellow "AD Property manager is not mapped to any user property"
        }
    }
    else
    {
        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.

Thank You.

share|improve this question
    
Your code cannot work as you're trying to do $connection.PropertyMapping. But $connection is the ConnectionManagerand doesn't have property mappings. –  Dennis G Feb 21 at 17:29
add comment

1 Answer

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
$props.RemovePropertyByName("Company")
share|improve this answer
    
Hello, can you tell me where exactly is the user profile property values stored? Is it against some list or waht? –  variable Mar 24 at 4:20
    
The database of course. Something you shouldn't touch ;-) –  Dennis G Mar 24 at 19:27
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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