Thursday, January 11, 2018

Find out all Site Collection Administrators from a Web Application using PowerShell


clear
Remove-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue
Add-PSSnapin Microsoft.SharePoint.Powershell

############### VARIABLES ################################

$rootsiteUrl = "https:/webappurl"

################################################################

$rootSite = New-Object Microsoft.SharePoint.SPSite($rootsiteUrl)
$spWebApp = $rootSite.WebApplication
 
foreach($site in $spWebApp.Sites)
{
    foreach($siteAdmin in $site.RootWeb.SiteAdministrators)
    {
        Write-Host "$($siteAdmin.ParentWeb.Url) - $($siteAdmin.DisplayName)"
    }
    $site.Dispose()
}
$rootSite.Dispose()

Remove Trusted Identity Token Issuer from SharePoint using PowerShell



clear 
Remove-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue 
Add-PSSnapin Microsoft.SharePoint.Powershell

Remove-SPTrustedIdentityTokenIssuer STSWebSite

Add Certificate SharePoint Trusted Root using PowerSHell



clear  
Remove-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue  
Add-PSSnapin Microsoft.SharePoint.Powershell 

$invocation = (Get-Variable MyInvocation).Value
$currentfolder = Split-Path $invocation.MyCommand.Path
$SolutionPath=$currentfolder + "\STSPublicCert.cer"
New-SPTrustedRootAuthority -Name "STSTrustRenewed" -Certificate $SolutionPath 

Renew FAST Search Certificate using PowerShell

This script is more useful for the environments that uses self signed certificates for FAST Search


###################################
# Apply Certificate to FAST
###################################

Clear
Remove-PSSnapin AdminSnapIn -ErrorAction SilentlyContinue
Remove-PSSnapin Microsoft.FASTSearch.PowerShell -ErrorAction SilentlyContinue
Remove-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

$userName = "Domain\ServiceAccountName"
$FastContentServiceName = "FAST Content"

write-host "Applying Certificate to FAST" -ForegroundColor Green
#Release worker processess with IISRESET
iisreset

stop-service FAST*

$installerdir = $env:FASTSEARCH + "installer\scripts"
echo $installerdir
cd $installerdir
$pw = ConvertTo-SecureString -AsPlainText -force test
.\ReplaceDefaultCertificate.ps1 -generateNewCertificate $true -certificatePassword $pw
$cert = @(dir cert:\LocalMachine\My -recurse | ? { $_.Subject -eq 'CN=FASTSearchCert' })[0]
$thumb = $cert.Thumbprint

Start-service FAST*

.\SecureFASTSearchConnector.ps1 -certThumbprint $thumb -ssaName $FastContentServiceName -username $userName

Generate DOCX to PDF file using Word Automation Service (WAS) in SharePoint using PowerShell


Note: This script will be very useful to test whether the WAS service is working properly in the environment. In addition, it will help to find out the source and destination libraries have proper permissions for the WAS to generate the PDF


clear  
Remove-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue  
Add-PSSnapin Microsoft.SharePoint.Powershell 

$webAppUrl = "http://webappurl"


[void][System.Reflection.Assembly]::LoadWithPartialName( "Microsoft.Office.Word.Server" ) 

$jobSettings = New-Object Microsoft.Office.Word.Server.Conversions.ConversionJobSettings 

$jobSettings.OutputFormat = "PDF" 

$job = New-Object Microsoft.Office.Word.Server.Conversions.ConversionJob( "Word Automation Services", $jobSettings ) 

$job.UserToken = (Get-SPWeb $webAppUrl).CurrentUser.UserToken 

#Provide the full document url with docx and pdf location

$job.AddFile( "http://webappurl/Shared%20Documents/test1.docx", "http://webappurl/Shared%20Documents/ConvertedDoc.pdf" ) 

$job.Start( )

write-host "Complete"

Access to XMLHttpRequest at 'from origin has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https. .net core angular

Issue: The angular application was getting error from API that the origin has been blocked by CORS policy. Solution: Make sure that the...