Friday, March 3, 2017

Powershell to Extend sharepoint web application, Add https binding to web application, Assign Existing Certificate to that binding

 

Add-PSSnapin Microsoft.SharePoint.PowerShell

$MachineName = [system.environment]::MachineName
$MachineNameFQDN = (Get-WmiObject win32_computersystem).DNSHostName+"."+(Get-WmiObject win32_computersystem).Domain

$WebAppAppPoolAccount = "AppPool Account"
$SiteCollectionOwner = "SiteCollection Owener Name"
$WebAppDatabaseServer = "Web App Data base (Content DB) server name"
$webApplication = "Web Application URL"

# Extend web application and Add Alternate Mappind to that Web applicaiton

$altMappingInternalURL = "http://"+$MachineNameFQDN
$webApplication | New-SPWebApplicationExtension -Name "Sharepoint Extended Web Application Name" -Port 83 -Zone "Custom" -Verbose -Url $altMappingInternalURL
Write-Host $altMappingInternalURL

# Extent Web Applicaiton

$webApplication | New-SPWebApplicationExtension -Name "Sharepoint Extended Web Applicaiton Name" -Port 121 -Zone "Internet" –Verbose

#Extend Web Application, Make that web application Form based

$webApplication = "http://Web Application URL/"
$sslProtocolURL = "Web Application URL"
$sslProtocolURL1 = "https://Web Application URL"
$ap = New-SPAuthenticationProvider -ASPNETRoleProviderName 'RolerProviderFBA' -ASPNETMembershipProvider 'MemberShipProviderFBA'
Get-SPWebApplication -Identity $webApplication | New-SPWebApplicationExtension -Name "Sharepoint Extended Web Applicaiton Name" -Port 82 -Zone "Internet"  -AuthenticationProvider $ap  -Verbose
New-SPAlternateUrl -URL $sslProtocolURL1 -WebApplication $webApplication -Zone "Internet" -Verbose

#Add WebBinding for HTTPS for Existing Web site and Assgine certificate to that biniding

$webSiteName = "Website Name";
Import-Module WebAdministration -ErrorAction SilentlyContinue
New-WebBinding -Name $webSiteName -HostHeader $sslProtocolURL -Protocol https -Port 443  -Verbose
Get-WebBinding $webSiteName
Get-ChildItem cert:\LocalMachine\My | where { $_.Subject -match "CN=CertificateName" } | select -First 1 | New-Item IIS:\SslBindings\0.0.0.0!443

No comments:

Post a Comment