title: Add a section in user properties using powershell in UPA sp2010
body: <p>I want to add a SECTION user property in UPA using powershell. I am executing the below script. It is executing for 1st time but getting error at ADD method in the second time.Also the property does not gets added</p>
  
  <pre><code>function CreateUserProfileSection()
  {     
    $site = Get-SPSite $xmlData.UserProfileSection.SiteURL
    function Get-SPServiceContext([Microsoft.SharePoint.Administration.SPServiceApplication] $profileApp)
      {
       $profileApp = @(Get-SPServiceApplication | ? {$_.TypeName -eq "User Profile Service Application"})[0]
       return [Microsoft.SharePoint.SPServiceContext]::GetContext($profileApp.ServiceApplicationProxyGroup,[Microsoft.SharePoint.SPSiteSubscriptionIdentifier]::Default)
      }
    $context = Get-SPServiceContext  
    $upcm = New-Object Microsoft.Office.Server.UserProfiles.UserProfileConfigManager($context);      
    $ppm = $upcm.ProfilePropertyManager
    $cpm = $ppm.GetCoreProperties()
    $ptpm = $ppm.GetProfileTypeProperties([Microsoft.Office.Server.UserProfiles.ProfileType]::User)
    $psm = [Microsoft.Office.Server.UserProfiles.ProfileSubTypeManager]::Get($context)
    $defaultSubType = [Microsoft.Office.Server.UserProfiles.ProfileSubtypeManager]::GetDefaultProfileName([Microsoft.Office.Server.UserProfiles.ProfileType]::User)
    $ps = $psm.GetProfileSubtype($defaultSubType)
  
    Write-Host "User Profile Objects setup complete"
    $Name = "testttttt"
    $pspm = $ps.Properties
    $Privacy1= "Public"
    $PrivacyPolicy1 ="Mandatory"
    $DisplayName1="Notifications Settings"
    $Description1 ="Custom2"
    #$xmlData.UserProfileSection.Section | ForEach-Object{
        $property = $pspm.GetSectionByName($Name)             
          if($property -eq $null)
          {
              $Privacy = $Privacy1
              $PrivacyPolicy=$PrivacyPolicy1
              $coreProp = $cpm.Create($true)
              $coreProp.Name = $Name
              $coreProp.DisplayName = $DisplayName1
              $coreProp.Description = $Description1
  
  
              $cpm.Add($coreProp)
              write-host -f green $_.Name section is created successfully             
          }
          else
          {
             write-host -f yellow $_.Name section already exists
          }
   #    }
   }
  
       #----------------Calling the function---------------------------------------------  
  CreateUserProfileSection
  </code></pre>