Tell me more ×
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

1 Answer

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.