在UPA sp2010中使用powershell在用户属性中添加一个部分

时间:2015-07-15 10:53:50

标签: powershell sharepoint user-profile

我想使用PowerShell在UPA中添加SECTION用户属性。我正在执行以下脚本。它正在第一次执行,但第二次在ADD方法中出错。此外,该属性未被添加

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

0 个答案:

没有答案