当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] 在 SharePoint 2016 中使用 PowerShell 创建 User Profile Service 应用程序

作者:精品下载站 日期:2024-12-14 14:41:58 浏览:17 分类:玩电脑

在 SharePoint 2016 中使用 PowerShell 创建 User Profile Service 应用程序


要求:在 SharePoint 2016 中创建用户配置文件服务应用程序。

我们需要 User Profile Service 应用程序来使用 SharePoint 2016 中的社交功能,例如“我的网站”、用户配置文件等。此 PowerShell 脚本在 SharePoint 2016 中创建 User Profile Service 应用程序。

先决条件:在创建用户配置文件服务应用程序之前创建我的网站主机。在 SharePoint 中使用 PowerShell 创建我的网站主机

PowerShell 在 SharePoint 2016 中创建用户配置文件服务应用程序

您是否正在寻找一种方法来自动化创建新用户配置文件服务应用程序的过程? PowerShell 可以帮助您做到这一点。让我向您展示如何使用 PowerShell 创建新的用户配置文件服务应用程序:


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
  
#Configuration Parameters
$ServiceAppName = "User Profile Service Application"
$ServiceAppProxyName = "User Profile Service Application Proxy"
$AppPoolAccount = "Crescent\SP16_Pool"
$AppPoolName = "Service Application App Pool"
$DatabaseServer ="SP16-SQL"
$UserProfileDB = "Farm_Profile_DB"
$UserProfileSyncDB = "Farm_Profile_Sync_DB"
$UserProfileSocialDB = "Farm_Profile_Social_DB"
$MySiteHostLocation="https://mysite.crescent.com/"

Try {
    #Set the Error Action
    $ErrorActionPreference = "Stop"
   
    #Check if Managed account is registered already
    Write-Host -ForegroundColor Yellow "Checking if the Managed Accounts already exists"
    $AppPoolAccount = Get-SPManagedAccount -Identity $AppPoolAccount -ErrorAction SilentlyContinue
    if($AppPoolAccount -eq $null)
    {
        Write-Host "Please Enter the password for the Service Account..."
        $AppPoolCredentials = Get-Credential $AppPoolAccount
        $AppPoolAccount = New-SPManagedAccount -Credential $AppPoolCredentials
    }
   
    #Check if the application pool exists already
    Write-Host -ForegroundColor Yellow "Checking if the Application Pool already exists"
    $AppPool = Get-SPServiceApplicationPool -Identity $AppPoolName -ErrorAction SilentlyContinue
    if ($AppPool -eq $null)
    {
        Write-Host -ForegroundColor Green "Creating Application Pool..."
        $AppPool = New-SPServiceApplicationPool -Name $AppPoolName -Account $AppPoolAccount
    }
   
    #Check if the Service application exists already
    Write-Host -ForegroundColor Yellow "Checking if User Profile Service Application exists already"
    $ServiceApplication = Get-SPServiceApplication -Name $ServiceAppName -ErrorAction SilentlyContinue
    if ($ServiceApplication -eq $null)
    {
        Write-Host -ForegroundColor Green "Creating User Profile Service  Application..."
        $ServiceApplication =  New-SPProfileServiceApplication -Name $ServiceAppName -ApplicationPool $AppPoolName -ProfileDBName $UserProfileDB -ProfileSyncDBName $UserProfileSyncDB -SocialDBName $UserProfileSocialDB -MySiteHostLocation $MySiteHostLocation
    }
    #Check if the Service application Proxy exists already
    $ServiceAppProxy = Get-SPServiceApplicationProxy | where { $_.Name -eq $ServiceAppProxyName}
    if ($ServiceAppProxy -eq $null)
    {
        #Create Proxy
        $ServiceApplicationProxy = New-SPProfileServiceApplicationProxy -Name $ServiceAppProxyName -ServiceApplication $ServiceApplication -DefaultProxyGroup        
    }
    #Start service instance
    $ServiceInstance  = Get-SPServiceInstance | Where-Object { $_.TypeName -eq "User Profile Service" }
   
    #Check the Service status
    if ($ServiceInstance.Status -ne "Online")
    {
        Write-Host -ForegroundColor Yellow "Starting the User Profile Service Instance..."
        Start-SPServiceInstance $ServiceInstance 
    }
   
    Write-Host -ForegroundColor Green "User Profile Service Application created successfully!"
}
catch {
    Write-Host $_.Exception.Message -ForegroundColor Red
 }
 finally {
    #Reset the Error Action to Default
    $ErrorActionPreference = "Continue"
} 

脚本执行成功完成后,您可以转到管理中心>>应用程序管理>>服务应用程序页面来验证用户配置文件服务应用程序是否已创建。

[玩转系统] 在 SharePoint 2016 中使用 PowerShell 创建 User Profile Service 应用程序

下一步:下一步是通过创建用户配置文件连接并启动完整配置文件导入来配置用户配置文件导入或同步。以下是如何添加用于用户配置文件导入的新连接:如何在 SharePoint 2016 中添加用户配置文件同步连接?

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯