Introduction

In Project Server 2016 Configuration article, we have explained How to Configure Project Server 2016 step by step?, In this article, we will show How to easily Configure Project Server 2016 using PowerShell Script?

Prerequisites

Before you getting started, you should make sure that
  1. Your farm is ready and the SharePoint 2016 Enterprise edition has been installed and configured successfully. 
  2. You have created the below service accounts: 
    • PSWebAppPool is a domain user that used to run the application pool for the web application that will host the PWA site collection.
    • PSSrvAppPool is a domain user that used to run the associated application pool of the project server service application.


How to use Project Server Configurator Script?

  1. Log in to the server as a farm account or any account that has elevated permission to run PowerShell as mentioned at Use Windows PowerShell to administer SharePoint.
  2. Download Project Server 2016 Configurator Script from The TechNet Gallery.
  3. Run Windows PowerShell ISE as Administrator.
  4. Open The "Final-PWA2016-V1.ps1" and set the below variables based on your environment.
[Variable Definition]

#Variables Definition
#######################################################
#Project Server Key
$ProjectServerKey           = "Y2WC2-K7NFX-KWCVC-T4Q8P-4RG9W" #Set the Project Server Key ("Y2WC2-K7NFX-KWCVC-T4Q8P-4RG9W" is a trail )
#######################################################
#Service Accounts variables
$PSWebAppPoolAccount        = "MQassas\PSWebAppPool" #A domain user that used to run the application pool of the web application that will host the PWA site collection.
$PSWebAppPoolPassWord       = "P@ssw0rd" # provide PSWebAppPool password
$PSSrvAppPoolAccount        = "MQassas\PSSrvAppPool" #A domain user that used to run the associated application pool of Project server service application.
$PSSrvAppPoolPassWord       = "P@ssw0rd" # provide PSSrvAppPool password
#######################################################
#Project Server Application Service variables
$PWAAppServiceAppPool       = "PWA_AppPool" # Project Server Application Service application pool name.
$PWAAppServiceApp           = "PWA_APP_SVC" # Project Server Application Service
#######################################################
#Web Application variables
$WebApplicationName         = "MQassas EPM 2016"
$WebApplicationAppPool      = "EPMAppPoool"
$WebApplicationUrl          = "http://mqassas"
$WebApplicationPort         = "8080"
$WebAppURL                  = $WebApplicationUrl +":" + $WebApplicationPort
$WebAppContentDataBaseName  = "WSS_Content_8080" # web application content database
$TopLevelSiteTitle          = "MQassas EPM 2016"
$TopLevelSiteOwnerAccount   = "mqassas\spfarm"
$TopLevelSiteTemplate       = "STS#0" # the site  template of root site collection, Note: for publishing site template set BLANKINTERNET#0
#######################################################
#PWA Instance variables
$PWAURL                     = $WebAppUrl + "/sites/PWA"
$PWAOwnerAccount            = "mqassas\spfarm" # the owner of PWA site
$PWAContentDataBaseName     = "PWA_Content_DB_8080"
#######################################################
#Database server
$DBServer                   = "MQassas\EPM" #SQL Server Instance.
#######################################################

Main Functions Script

The Project Server 2016 Configurator script includes the below functions 

#1 - Register Managed Accounts.
#2 - Enable Project Server 2016 License.
#3 - Create Project Server Application Service Application Pool.
#4 - Create a Project Server 2016 service application.
#5 - Create a web Application.
#6 - Create Top Level site Collection. 
#7 - Lock Down web application Content Database.
#8 - Create a PWA Content Database.
#9 - Lock Down PWA Content Database.
#10 - Provision the PWA Site Collection.
#11 - Enable PWA FeatureStart PWA Instance.
#12 - Start PWA Instance.


Script in details

In this section, we will explore the Project Server 2016 Configurator functions in details.

Register Managed Accounts


In this function, we will make sure that the required service accounts (PSWebAppPool - PSSrvAppPool) have been added to Managed Accounts.
  1. In case. the service accounts are already added to Managed Account, then inform me that.
  2. In case, the service accounts are not added to Managed Account, then add it.
[Function Definition]

#Add service accounts to managed account
function Add-ManagedAccount()
    {
    param ([string]$ServiceAccount,[string]$AccountPassword)
        Try
        {
            Write-Host "Adding the service Account" $ServiceAccount "to Managed Account" -ForegroundColor Green
            $srvacount = Get-SPManagedAccount | ?  {$_.UserName -eq $ServiceAccount}
            if ($srvacount -eq $null)
            {
                $pass = convertto-securestring $AccountPassword -asplaintext -force
                $cred = new-object management.automation.pscredential $ServiceAccount ,$pass
                $res  = New-SPManagedAccount -Credential $cred
                if ($res -ne $null)
                {
                    Write-Host "The" $ServiceAccount "has been added successfully to Managed Account" -ForegroundColor Cyan
                }
            }
            else
            {
                Write-Host "The" $ServiceAccount "is already added to Managed Account" -ForegroundColor Yellow
            }    
        }
        Catch
        {
            Write-Host $_.Exception.Message -ForegroundColor Red
        }
    }

[Function Call]

#Register Managed Account.
#Add PSWebAppPoolAccount Account
Add-ManagedAccount -ServiceAccount $PSWebAppPoolAccount -AccountPassword $PSWebAppPoolPassWord
 
#Add PSSrvAppPool Account
Add-ManagedAccount -ServiceAccount $PSSrvAppPoolAccount -AccountPassword $PSSrvAppPoolPassWord

[Output]

Project Server 2016 Configurator Script

Enable Project Server License


In this function, we will enable the Project Server 2016 License.

[Function Definition]

#Enable ProjectServer License.
function Activate-PSLicense()
    {
    param ([string]$PSKey)
        Try
        {
            Write-Host "Enable ProjectServer License" -ForegroundColor Green
            $res =  Enable-ProjectServerLicense -Key $PSKey
            if ($res -ne $null)
            {
                Write-Host "The Project Server License has been enabled successfully" -ForegroundColor Cyan
            }
        }
        Catch
        {
            Write-Host $_.Exception.Message -ForegroundColor Red
        }
    }

[Function Call]

#Enable ProjectServer License.
Activate-PSLicense -PSKey $ProjectServerKey

[Output]

Project Server 2016 Configurator Script

Create Project Server Application Service Application Pool


In this function, we will create an Application Pool for the Project Server Service Application.

[Function Definition]

#Create Project Server Application Service Application Pool.
function Create-PWASvcAppPool()
    {
    param ([string]$PWASvcAppPool,[string]$PWASvcAppPoolAccount)
        Try
        {
            Write-Host "Create Project Server Application Service Application Pool" -ForegroundColor Green
            $res = New-SPServiceApplicationPool  -Name $PWASvcAppPool -Account $PWASvcAppPoolAccount
            if ($res -ne $null)
            {
                Write-Host "Project Server Application Service Application Pool " $PWASvcAppPool " has been created successfully" -ForegroundColor Cyan
            }
        }
        Catch
        {
            Write-Host $_.Exception.Message -ForegroundColor Red
        }
    }

[Function Call]

#Create Project Server Application Service Application Pool.
Create-PWASvcAppPool -PWASvcAppPool $PWAAppServiceAppPool -PWASvcAppPoolAccount $PSSrvAppPoolAccount

[Output]

Project Server 2016 Configurator Script

Create a Project Server Service Application


In this function, we will create the Project Server Service Application.

[Function Definition]

#Create Project Server Application Service.
function Create-PWASvc()
    {
    param ([string]$PWASvcName,[string]$PWASvcAppPool)
        Try
        {
            Write-Host "Create Project Server Application Service" -ForegroundColor Green
            $res = New-SPProjectServiceApplication –Name $PWASvcName –ApplicationPool $PWASvcAppPool –Proxy
            if ($res -ne $null)
            {
                Write-Host "Project Server Application Service " $PWASvcName " has been created successfully" -ForegroundColor Cyan
            }
        }
        Catch
        {
            Write-Host $_.Exception.Message -ForegroundColor Red
        }
    }

[Function Call]

#Create Project Server Application Service.
Create-PWASvc -PWASvcName $PWAAppServiceApp -PWASvcAppPool $PWAAppServiceAppPool

[Output]

Project Server 2016 Configurator Script

Create a Web Application


In this function, we will the web application that will host the PWA Instance.

[Function Definition]

#Create a Web Application.
function Create-WebApplication()
    {
    param ([string]$WebAppName,[int]$port,[string]$WebAppURL,[string]$WebAppContentDB,[string]$DBServer,[string]$WebAppPool,[string]$WebAppPoolAccount)
        Try
        {
            Write-Host "Create A web Application" -ForegroundColor Green
            $res = New-SPWebApplication -Name $WebAppName -port $port -URL $WebAppURL -DatabaseName $WebAppContentDB -DatabaseServer $DBServer -AuthenticationMethod NTLM -ApplicationPool $WebAppPool -ApplicationPoolAccount $WebAppPoolAccount
            if ($res -ne $null)
            {
                Write-Host "A new web application " $WebAppName " has been created successfully" -ForegroundColor Cyan
            }
        }
        Catch
        {
            Write-Host $_.Exception.Message -ForegroundColor Red
        }
    }

[Function Call]

#Create a Web Application.
Create-WebApplication -WebAppName $WebApplicationName -port $WebApplicationPort -WebAppURL $WebApplicationUrl -WebAppContentDB $WebAppContentDataBaseName -DBServer $DBServer -WebAppPool $WebApplicationAppPool -WebAppPoolAccount $PSWebAppPoolAccount

[Output]

Project Server 2016 Configurator Script

Create Top Level site Collection


In this function, we will create the Top Level Site Collection.

[Function Definition]

#Create Top Level Site Collection
function Create-TopLevelSiteCollection()
    {
    param ([string]$webURL,[string]$siteOwner,[string]$siteName,[string]$siteTemplate)
        Try
        {
            Write-Host "Create Top Level Site Collection" -ForegroundColor Green
            $res = New-SPSite $WebAppURL -OwnerAlias $siteOwner  -Name $siteName -Template $siteTemplate
            if ($res -ne $null)
            {
                Write-Host "Top Level Site Collection " $siteName " has been created successfully" -ForegroundColor Yellow
                START $WebAppURL
            }
        }
        Catch
        {
            Write-Host $_.Exception.Message -ForegroundColor Red
        }
}

[Function Call]

#Create Top Level site Collection.
Create-TopLevelSiteCollection -webURL $WebURL -siteOwner $TopLevelSiteOwnerAccount -siteName $TopLevelSiteTitle -siteTemplate $TopLevelSiteTemplate

[Output]

Project Server 2016 Configurator Script
Project Server 2016 Configurator Script

Lock Down Web Application Content Database


It's recommended to isolate the PWA content database from Web Application content database. so, in this function, we will lock down the main content database of the web application. For more details check Content database consideration during provisioning a new PWA instance in Project Server.


[Function Definition]

#Lock Down web application Content Database.
function LockDown-ContentDatabase()
    {
    param ([string]$ContentDataBaseName,[int]$MaxSiteCount,[int]$WarningSiteCount)
        Try
        {
            #Get-SPContentDatabase | ? {$_.Name -eq $ContentDataBaseName}
            Write-Host "Lock Down web application Content Database" -ForegroundColor Green
            $res = Set-SPContentDatabase -Identity $ContentDataBaseName -MaxSiteCount $MaxSiteCount -WarningSiteCount $WarningSiteCount
            if ($res -ne $null)
            {
                Write-Host "The Content Database " $ContentDataBaseName " has been locked successfully" -ForegroundColor Yellow
            }
        }
        Catch
        {
            Write-Host $_.Exception.Message -ForegroundColor Red
        }
    }

[Function Call]

#Lock Down web application Content Database.
LockDown-ContentDatabase -ContentDataBaseName $WebAppContentDataBaseName -MaxSiteCount 1 -WarningSiteCount 0

[Output]


Create a PWA Content Database


In this function, we will create an independent content database for PWA Instance.

[Function Definition]

#Create A new PWA Content Database.
function Create-ContentDatabase()
    {
    param ([string]$PWAContentDataBaseName,[string]$DBServer,[string]$WebAppUrl)
        Try
        {
            Write-Host "Create A new PWA Content Database" -ForegroundColor Green
            $res = New-SPContentDatabase $PWAContentDataBaseName -DatabaseServer $DBServer -WebApplication $WebAppUrl
            if ($res -ne $null)
            {
                Write-Host "The PWA Content Database " $PWAContentDataBaseName " has been created successfully" -ForegroundColor Yellow
            }
        }
        Catch
        {
            Write-Host $_.Exception.Message -ForegroundColor Red
        }
    }

[Function Call]

#Create A new PWA Content Database.
Create-ContentDatabase -PWAContentDataBaseName $PWAContentDataBaseName  -DBServer $DBServer -WebAppUrl $WebAppURL

[Output]

Project Server 2016 Configurator Script

Lock Down PWA Content Database


Again, we will lock down the PWA Content Database to prevent any new site collection to be created in it.

[Function Definition]

#Lock Down PWA Content Database.
function LockDown-ContentDatabase()
    {
    param ([string]$ContentDataBaseName,[int]$MaxSiteCount,[int]$WarningSiteCount)
        Try
        {
            #Get-SPContentDatabase | ? {$_.Name -eq $ContentDataBaseName}
            Write-Host "Lock Down Content Database" -ForegroundColor Green
            $res = Set-SPContentDatabase -Identity $ContentDataBaseName -MaxSiteCount $MaxSiteCount -WarningSiteCount $WarningSiteCount
            if ($res -ne $null)
            {
                Write-Host "The Content Database " $ContentDataBaseName " has been locked successfully" -ForegroundColor Yellow
            }
        }
        Catch
        {
            Write-Host $_.Exception.Message -ForegroundColor Red
        }
    }

[Function Call]

#Lock Down PWA Content Database.
LockDown-ContentDatabase -ContentDataBaseName $PWAContentDataBaseName -MaxSiteCount 1 -WarningSiteCount 0

[OutPut]


Provision the PWA Site Collection


In this function, we will create the PWA Site Collection.

[Function Definition]

#Provision PWA Instance.
function Provision-PWAInstance()
    {
    param ([string]$PWAContentDataBaseName,[string]$siteOwner,[string]$PWAURL)
        Try
        {
            Write-Host "Provision PWA Instance" -ForegroundColor Green
            $res = New-SPSite -ContentDatabase $PWAContentDataBaseName -URL $PWAURL -Template pwa#0 -OwnerAlias $siteOwner
            if ($res -ne $null)
            {
                Write-Host "The PWA Instance " $PWAURL " has been created successfully" -ForegroundColor Yellow
            }
        }
        Catch
        {
            Write-Host $_.Exception.Message -ForegroundColor Red
        }
    }

[Function Call]

#Provision PWA Instance.
Provision-PWAInstance -PWAContentDataBaseName $PWAContentDataBaseName -PWAURL $PWAURL -siteOwner $PWAOwnerAccount

[Output]

Project Server 2016 Configurator Script

Enable PWA Feature


In this function, we will enable the PWA Feature on the PWA Site Collection to be ready in use as PWA Instance with Project Server Capabilities. 

[Function Definition]

#Enable PWA Feature.
function Enable-PWAFeature()
    {
    param ([string]$PWAURL)
        Try
        {
            Write-Host "Enable PWA Feature" -ForegroundColor Green
            $res = Enable-SPFeature pwasite -URL $PWAURL
            if ($res -ne $null)
            {
                Write-Host "The PWA feature " $PWAContentDataBaseName " has been enabled successfully" -ForegroundColor Yellow
            }
        }
        Catch
        {
            Write-Host $_.Exception.Message -ForegroundColor Red
        }
    }

[Function Call]

#Enable PWA Feature.
Enable-PWAFeature -PWAURL $PWAURL

[Output]


Start PWA Instance


In this function, we will browse the PWA Instance to make sure that the PWA instance has been created successfully.

[Function Definition]

#Browse PWA Instance.
function Browse-PWA()
    {
    param ([string]$PWAURL)
        Try
        {
            Write-Host "Start" $PWAURL -ForegroundColor Green
            START $PWAURL
        }
        Catch
        {
            Write-Host $_.Exception.Message -ForegroundColor Red
        }
    }

[Function Call]

#Browse PWA Instance.
Browse-PWA $PWAURL

[Output]

Project Server 2016 Configurator Script

Download

Download the Full Project Server 2016 Configurator Script from TechNet Gallery.

Conclusion

In this article, we have explained How to Configure Project Server 2016 via PowerShell?

See also

Project Server 2016 Configuration.