Emad GabrielThoughts, tips and shortcuts about building software
SharePoint

SharePoint PowerShell script to create SPWebApplication with Custom membership provider and Claims based authentication

$webAppName = "Contoso Internet Site XYZ" $webAppUrl = "http://www.contoso.com" $webAppPort = 80 $webAppHostHeader = "sharepoint.contoso.com" $membershipProviderName = "OAMMembershipProvider" $roleProviderName = "OAMRoleProvider" $appPoolName = "ContosoAppPool" $contentDBName = "Contoso" $appPoolUser =  "DE\sp_AppPool"

Write-Host "Deleting Web application $webApp if it exists..."
Remove-SPWebApplication -Identity $webAppUrl -Confirm:$false -Verbose -DeleteIISSite:$true -RemoveContentDatabases:$true -ErrorAction SilentlyContinue

$formsAuthProvider = New-SPAuthenticationProvider -ASPNETMembershipProvider $membershipProviderName -ASPNETRoleProviderName $roleProviderName
$windowsAuthProvider = New-SPAuthenticationProvider
$AuthProvidersArray = $formsAuthProvider, $windowsAuthProvider

New-SPWebApplication -Name $webAppName -Port $webAppPort -HostHeader $webAppHostHeader -URL $webAppUrl -ApplicationPool $appPoolName -ApplicationPoolAccount (Get-SPManagedAccount $appPoolUser) -AllowAnonymousAccess -AuthenticationProvider $AuthProvidersArray -AuthenticationMethod NTLM -Verbose -DatabaseName $contentDBName  -ErrorVariable $ev
if($ev -ne $null)
{
Write-Host "Web Application $webApp created successfully"
}

$webApp = get-SPWebApplication $webAppUrl
$webApp.UseClaimsAuthentication = $true
$webApp.Update()
Write-Host "Updated Web application to use claims based authentication for $webApp.."

PowerShellSharePoint 2010