Create User Profile Service Application using PowerShell in SharePoint 2016
Requirement: Create the user profile service application in SharePoint 2016.
We need the User Profile Service Application to consume social features in SharePoint 2016, such as My Sites, User profiles, etc. This PowerShell script creates User Profile Service Application in SharePoint 2016.
PowerShell to create user profile service application in SharePoint 2016
Are you looking for a way to automate the process of creating new user profile service applications? PowerShell can help you do just that. Let me show you how to create a new user profile service application using 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"
}
Once the script execution is completed successfully, you can go to Central Administration >> Application Management >> Service Application Page to verify user profile service application is created.
Next step: The next step is configuring user profile Import or synchronization by creating a user profile connection and starting a full profile import. Here is how to add a new connection for user profile import: How to Add a user profile synchronization connection in SharePoint 2016?
Awcum Salaudeen,
I read your all articles ,honestly your great jobs,If you don’t mind I want to request to you please create a separate label of article for SP RestAPI with real word scenario based.
Hello Salaudeen,
just found your blog – and I’m quite happy I did. As a beginner the script helps me understand things quicker 🙂
Thanks again and greetings from Germany
Tobias