domingo, 17 de julio de 2016

Parte 6–SharePoint 2016 Creación de web application

Indice de Instalación de Sharepoint 2016

En esta parte, creo un web application http://intra.contoso.com

Uso 3 cuentas:

  • svcspwapp: Sharepoint Web Application Account, cuenta de identidad para ejecutar los application pools del IIS
  • svcspsprusr:  Sharepoint SuperUser, cuenta para acceder al web application con Full Read access (auditoria/caching)
  • svcspsprread: Sharepoint SuperReader cuenta para acceder al web application con Full Control access (auditoria/caching)

 

Descargar Script

$ver = $host | select version

if($Ver.version.major -gt 1) {$Host.Runspace.ThreadOptions = "ReuseThread"}

if(!(Get-PSSnapin Microsoft.SharePoint.PowerShell -ea 0))
{
    Add-PSSnapin Microsoft.SharePoint.PowerShell
}

Write-Progress -Activity "Creando Web Application" -Status "Seteando Variables"
##CONFIGURACIÓN

# Web Application URL
$WebApplicationURL = "http://intra.contoso.com"

# Nombre para el SharePoint Web Application
$WebApplicationName = "Intra Web Application"

# Content Database para el web application
$ContentDatabase = "Intra_ContentDB1"

# Nombre para el Application Pool
$ApplicationPoolDisplayName = "Intra App Pool"

# Identidad para el Application Pool (domain\user)
$ApplicationPoolIdentity = "CONTOSO\svcspwapp"

# Password para el Application Pool
$ApplicationPoolPassword = "xxxxxxxxxx"

# Cuenta para Super Reader
$PortalSuperReader = "i:0#.w|CONTOSO\svcspsprread"

# Cuenta para Super User
$PortalSuperUser = "i:0#.w|CONTOSO\svcspsprusr"

Write-Progress -Activity "Creando Web Application" -Status "Loading Functions"


Function CrearClaimsWebApp($WebApplicationName, $WebApplicationURL, $ContentDatabase, $HTTPPort)
{
    $ap = New-SPAuthenticationProvider
   
    if($AppPoolUsed -eq $True)
    {
        Write-Progress -Activity "Creating Web Application" -Status "Using Application Pool With Existing Web Applications"
        Set-Variable -Name WebApp -Value (New-SPWebApplication -ApplicationPool $ApplicationPoolDisplayName -Name $WebApplicationName -url $WebApplicationURL -port $HTTPPort -DatabaseName $ContentDatabase -HostHeader $hostHeader -AuthenticationProvider $ap) -Scope Script
       

        Write-Progress -Activity "Creating Web Application" -Status "Configuring Object Cache Accounts"
        SetObjectCache
       
    }
    else
    {       
        Write-Progress -Activity "Creating Web Application" -Status "Using Application Pool With No Existing Web Applications"
        Set-Variable -Name WebApp -Value (New-SPWebApplication -ApplicationPool $ApplicationPoolDisplayName -ApplicationPoolAccount $AppPoolManagedAccount.Username -Name $WebApplicationName -url $WebApplicationURL -port $HTTPPort -DatabaseName $ContentDatabase -HostHeader $hostHeader -AuthenticationProvider $ap) -Scope Script
       
        Write-Progress -Activity "Creating Web Application" -Status "Configuring Object Cache Accounts"
        SetObjectCache
       
    }
}

Function ValidarURL($WebApplicationURL)
{
    if(get-spwebapplication $WebApplicationURL -ErrorAction SilentlyContinue)
    {
        Write-Progress -Activity "Creando Web Application" -Status "Abortando proceso debido a un conflicto de URL"
        Write-Host "Abortando: Web Application $WebApplicationURL ya existe" -ForegroundColor Red
      
        #Seteo el valor CriticalError a $True resultado en NO crear nada
        Set-Variable -Name CriticalError -Value $True
    }  
    elseif($WebApplicationURL.StartsWith("http://"))
        {
            Set-Variable HostHeader -Value ($WebApplicationURL.Substring(7)) -Scope Script
            Set-Variable -Name HTTPPort -Value "80" -Scope Script
        }
        elseif($WebApplicationURL.StartsWith("https://"))
        {
            Set-Variable HostHeader -Value ($WebApplicationURL.Substring(8)) -Scope Script
            Set-Variable -Name HTTPPort -Value "443" -Scope Script
        }
}

Function ValidarAppPool($AppPoolName, $WebApplicationURL)
{
    $CurrentErrorActionPreference = $ErrorActionPreference
    $ErrorActionPreference = "SilentlyContinue"

    #Verifica si existe un application pool con el nombre pasado como parametro   
    $TestAppPool = Get-WebAppPoolState $AppPoolName

    if(Get-SPServiceApplicationPool $AppPoolName)
    {
        $AppPools = Get-SPWebApplication | select ApplicationPool

        if($AppPools)
        {
            foreach($Pool in $AppPools)
            {
              
                [Array]$Poolchild = $Poolchild += ($Pool.ApplicationPool.DisplayName)

                if($Poolchild.Contains($ApplicationPoolDisplayName))
                {
                    Set-Variable -Name AppPoolUsed -Value $True -Scope Script
                }

                else
                {
                    Set-Variable -Name AppPoolUsed -Value $False -Scope Script
                }
            }
        }
       
        Set-Variable -Name AppPool -Value (Get-SPServiceApplicationPool $AppPoolName) -scope Script

        Set-Variable -Name AppPoolManagedAccount -Value (Get-SPManagedAccount | ? {$_.username -eq ($AppPool.ProcessAccountName)}) -scope Script
    }
    elseif($TestAppPool)
    {
        Write-Host "Aborting: Application Pool $AppPoolName already exists on the server and is not a SharePoint Application Pool `n`rWeb Application `"$WebApplicationURL`" will not be created" -ForegroundColor Red
        Set-Variable -Name CriticalError -Value $True
    }
    elseif(!($TestAppPool))
    {
        ValidarManagedAccount $ApplicationPoolIdentity

        if($ManagedAccountExists -eq $True)
        {
            Write-Host "Creating New App Pool using Existing Managed Account"
            Set-Variable -Name AppPoolManagedAccount -Value (Get-SPManagedAccount $ApplicationPoolIdentity | select username) -scope "Script"

            Set-Variable -Name AppPool -Value (New-SPServiceApplicationPool -Name $ApplicationPoolDisplayName -Account $ApplicationPoolIdentity) -scope "Script"
        }
        else
        {
            Write-Host "Creating New Managed Account And App Pool"
            $AppPoolCredentials = New-Object System.Management.Automation.PSCredential $ApplicationPoolIdentity, (ConvertTo-SecureString $ApplicationPoolPassword -AsPlainText -Force)
           
            Set-Variable -Name AppPoolManagedAccount -Value (New-SPManagedAccount -Credential $AppPoolCredentials) -scope "Script"
           
            Set-Variable -Name AppPool -Value (New-SPServiceApplicationPool -Name $ApplicationPoolDisplayName -Account (get-spmanagedaccount $ApplicationPoolIdentity)) -scope "Script"
        }

    }
   
    $ErrorActionPreference = $CurrentErrorActionPreference

}

Function ValidarManagedAccount($ApplicationPoolIdentity)
{
    if(Get-SPManagedAccount $ApplicationPoolIdentity -ErrorAction SilentlyContinue)
    {
        Set-Variable -Name ManagedAccountExists -Value $True -Scope Script
    }
    else
    {
        Set-Variable -Name ManagedAccountExists -Value $False -Scope Script
    }
}

Function LimpiarVariables
{
    $CurrentErrorActionPreference = $ErrorActionPreference
    $ErrorActionPreference = "SilentlyContinue"

    Remove-Variable $CriticalError -ErrorAction SilentlyContinue
    $ErrorActionPreference = $CurrentErrorActionPreference
}

Function SetObjectCache
{
    $WebApp.Properties["portalsuperuseraccount"] = $PortalSuperUser
    $WebApp.Properties["portalsuperreaderaccount"] = $PortalSuperReader
    
    #Creo una nueva policy para el Super User
    $SuperUserPolicy = $WebApp.Policies.Add($PortalSuperUser, "Portal Super User Account")
    #Asigno Full Control al Super User
    $SuperUserPolicy.PolicyRoleBindings.Add($WebApp.PolicyRoles.GetSpecialRole([Microsoft.SharePoint.Administration.SPPolicyRoleType]::FullControl))
   
    #Creo una nueva policy para el Super Reader
    $SuperReaderPolicy = $WebApp.Policies.Add($PortalSuperReader, "Portal Super Reader Account")   
    #Asigno Full Read al Super Reader
    $SuperReaderPolicy.PolicyRoleBindings.Add($WebApp.PolicyRoles.GetSpecialRole([Microsoft.SharePoint.Administration.SPPolicyRoleType]::FullRead))

    #Commit these changes to the web application
    $WebApp.Update()
}


Write-Progress -Activity "Creando Web Application" -Status "Validando las URL del Web Application"
ValidarURL $WebApplicationURL

Write-Progress -Activity "Creando Web Application" -Status "Validando los Pools de los Application"
ValidarAppPool $ApplicationPoolDisplayName $WebApplicationURL


if(!($CriticalError))
{
    Write-Progress -Activity "Creando Web Application" -Status "Creando Claims-Based Web Application"
    CrearClaimsWebApp $WebApplicationName $WebApplicationURL $ContentDatabase $HTTPPort
}

1 comentario: