Ads

Tuesday, 11 April 2017

How to create self-signed certificate & bind with SharePoint web application

Hi,
To achieve this we need to follow below steps.
  1. Create any SharePoint web application 
    • Create a normal web application from central admin site. below are few details
    • Name = learning
    • Host header = www.learning.com
    • port = 8082
    • public URL look like = http://www.learning.com:8082
  2. Create self-signed certificate from IIS 
    • Go to IIS --> Select main node(Computer Name) --> Server  Certificates --> Create Self-Signed Certificate (from right pane) --> enter details like name & Store as personal --> Ok
    • Do IISRESET
  3. Bind the certificate with newly created web application
    • Go to IIS --> Expand main node(Computer Name) --> expand sites node -->  select your site --> bindings from right pane --> add new bindings here
    • select type as "https", host name, select your created certificate as shown below
    •  
    •  
  4. Export newly created certificate from server certificates
    • Go to IIS --> Select main node(Computer Name) --> Server  Certificates --> double click newly created certificate --> details tab --> click copy to file --> proceed with next click
  5.  Import certificate in SharePoint certificate store
    1. Open Manage Compute Certificate on Windows Server 2012 --> Expand SharePoint node --> then right-click --> All tasks > Import --> Click Next and then specify the location of the exported certificate in above step --> Click Next --> Make sure Certificate store is SharePoint --> Click Next and then Finish. 
  6. Add self signed certificate to SharePoint central administration
    1. Go to Central Administration > Security > Manage Trust --> click New 
    2. Enter Name and specify the location for the certificate --> Click OK. 
  7. Do alternate access mapping for your web application
    1. Do the alternate access mapping like below








Friday, 7 April 2017

REST with Search in SharePoint

In SharePoint 2013, There are few REST end points which are used to retrieve search results.
  • Site Coll Url.../_api/search/query
  • Site Coll Url.../_api/search/postquery
  • Site Coll Url.../_api/search/suggest
Below are few search URLs to query search results..
Set maximum number of record to return
/_api/search/query?querytext='search term'&rowlimit=100
Set index of start row
/_api/search/query?querytext='search term'&startrow=11
Specify a number of results to return
/_api/search/query?querytext='search term'&startrow=11&rowlimit=10 (but note 10 is the default)
Specifies the list of properties to sort the search results by.
/_api/search/query?querytext=’terms’&sortlist= ‘Title:ascending’
Specify particular (managed) properties to return
/_api/search/query?querytext='search term'&selectproperties='Author,Path,Title'
Use a search Result Source (i.e. a scope)
/_api/search/query?querytext='search term'&sourceid='B09A7990-05EA-4AF9-81EF-EDFAB16C4E31' (this ex. is to search the ‘People’ result source)

In above table, The last one is used to query results from any document library which GUID is passed as sourceid in search query URL. We can also replaced this ID with other GUIDs given below to get the result from specific result sources.

Result Source
ID
Documents
e7ec8cee-ded8-43c9-beb5-436b54b31e84
Items matching a content type
5dc9f503-801e-4ced-8a2c-5d1237132419
Items matching a tag
e1327b9c-2b8c-4b23-99c9-3730cb29c3f7
Items related to current user
48fec42e-4a92-48ce-8363-c2703a40e67d
Items with same keyword as this item
5c069288-1d17-454a-8ac6-9c642a065f48
Local People Results
b09a7990-05ea-4af9-81ef-edfab16c4e31
Local Reports And Data Results
203fba36-2763-4060-9931-911ac8c0583b
Local SharePoint Results
8413cd39-2156-4e00-b54d-11efd9abdb89
Local Video Results
78b793ce-7956-4669-aa3b-451fc5defebf
Pages
5e34578e-4d08-4edc-8bf3-002acf3cdbcc
Pictures
38403c8c-3975-41a8-826e-717f2d41568a
Popular
97c71db1-58ce-4891-8b64-585bc2326c12
Recently changed items
ba63bbae-fa9c-42c0-b027-9a878f16557c
Recommended Items
ec675252-14fa-4fbe-84dd-8d098ed74181
Wiki
9479bf85-e257-4318-b5a8-81a180f5faa1








Thursday, 6 April 2017

PowerShell to get all site collections details like URL, Root Template, Contnet DB in CSV file

Below is the full script with all functions that can be used to retrieve site collection details like URL, Site ID, Template name, Size of site, Content DB. Follow the steps
  1. Copy all below contents in one text file 
  2. Provide the web application URL
  3. Change the extension of text file from .txt to .ps1 file. (Like - GetAllSites.ps1
  4. Execute this .ps1 file (GetAllSites.ps1) in SharePoint management shell

#Start:  Custom Variable Entry
$webAppUrl = "Your Web Application URL Here"
#End: Custom Variable Entry

if ((Get-PSSnapin -Name Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue) -eq $null )
{
    Add-PSSnapin Microsoft.SharePoint.Powershell
}
function Execute-GetAllSites
{
    $WebApplication = Get-SPWebApplication -Identity $webAppUrl
   
    if ($WebApplication -ne $null)
     {
        foreach ($SiteCollection in  $WebApplication.Sites)
        {
            Try
            {
                if ($SiteCollection -ne $null)
                {                   
                    $SiteTitle = $SiteCollection.RootWeb.Title
                    Write-Host "$($SiteTitle.Substring(0,1))"  -NoNewLine
                   
                    $RootWeb = $SiteCollection.RootWeb
                    $WebTemplate = $RootWeb.WebTemplate
                   
                    #$Size = [string]$SiteCollection.Usage.Storage/1000000
                    $SizeinMB = [System.Math]::Round((($SiteCollection.Usage.Storage)/1MB),2)
                   
                    $contentDB = $SiteCollection.ContentDatabase.Name
                   
                    Write-Excel-SiteCollections $LogFile_Excel $SiteCollection.Url $SiteCollection.ID $WebTemplate $SizeinMB $contentDB
                   
                    
                    $SiteCollection.Dispose()      
                }
            }
            Catch {}                      
        }
       
        Write-Host "----- Complete -----"
     }   
}
function Get_DateTime()
{
    $LogFileDayF = Get-Date -Format "s";
    $LogFileDateTime = $LogFileDayF.Replace(":","_")                          
    return $LogFileDateTime;
}
Function CreateExcelLogFile($LogFileName)
{   
    $logFilePath ="";
    $Date_Time = Get_DateTime   
    Try
    {       
        #$JobLogPath = $CurrentPath | Join-Path -ChildPath ("Log_AdminReport")
        $JobLogPath = $CurrentPath
    
        #Create folder path if not exists
        if(!(Test-Path $JobLogPath))
        {
           New-Item -Path $JobLogPath -ItemType directory
        }
        $JobLogPath = $JobLogPath + "\" + $LogFileName + "_" + $Date_Time + ".csv"
    }
    Catch
    {}     
    return $JobLogPath
}
function Write-Excel-SiteCollections($logFilePath,$SiteCollectionUrl,$SiteCollectionID, $WebTemplate, $Size, $contentDB)
{   
    $SiteCollectionUrl = $SiteCollectionUrl.Replace(',','%2C')
   
    if((Test-Path $logFilePath) -eq $false)
    {
        New-Item $logFilePath -type file | Out-Null
        Add-Content -Path $logFilePath -Value 'Site Collection URL,Site Collection ID,Root Web Template, Size in MB, Content DB Name'
    }

    $msg = "$($SiteCollectionUrl),$($SiteCollectionID),$($WebTemplate),$($Size),$($contentDB)"
    Add-Content -path $logFilePath -value $msg
}
function Get-ScriptDirectory
{
  $Invocation = (Get-Variable MyInvocation -Scope 1).Value
  Split-Path $Invocation.MyCommand.Path
}
#----------- Main Start point that execute ----------
$CurrentPath = Get-ScriptDirectory
$LogFile_Excel = CreateExcelLogFile 'AllSiteDetails'
Execute-GetAllSites

Result Output in CSV file


Some recommendations for you:
Powershell to create & write result output in CSV file as per need  
Powershell script to read CSV file to do any automation


Wednesday, 5 April 2017

Powershell to create & write result output in CSV file as per need

Write below functions to achieve the same

---------------- Function that will receive CSV file name and create one CSV file -----------
 Function CreateExcelLogFile($LogFileName)  #$LogFileName is the output CSV file name
{
    $Date_Time = Get_DateTime #Call a function to get DateTime to append in output csv file
    $CurrentPath = Get-ScriptDirectory #Call function to get current file path

    Try
    {       
        $JobLogPath = $CurrentPath            
        if(!(Test-Path $JobLogPath))  #Create folder path if not exists
        {
           New-Item -Path $JobLogPath -ItemType directory
        }
        $JobLogPath = $JobLogPath + "\" + $LogFileName + "_" + $Date_Time + ".csv"
    }
    Catch
    { }   
    return $JobLogPath
}
----------------------- Function to get the current execution Script path ---------------------
function Get-ScriptDirectory
{
  $Invocation = (Get-Variable MyInvocation -Scope 1).Value
  Split-Path $Invocation.MyCommand.Path
}
----------------------- Function to get date time to append in output file ---------
function Get_DateTime()
{
    $LogFileDayF = Get-Date -Format "s";
    $LogFileDateTime = $LogFileDayF.Replace(":","_")                          
    return $LogFileDateTime;
}
----------------------- Function to write in CSV file -----------
function Write-To-Excel-File($logFilePath, $Column1_Value, $Column2_SiteURL)
{   
    $Column2_SiteURL = $Column2_SiteURL.Replace(',','%2C') #Replace , with %20
    if((Test-Path $logFilePath) -eq $false)
    {
        New-Item $logFilePath -type file | Out-Null
        Add-Content -Path $logFilePath -Value 'Column1 Header,Column2 Header'
    }

    $msg = "$($Column1_Value),$($Column2_SiteURL)"
    Add-Content -path $logFilePath -value $msg
}
---------------------- Main execution point to call different functions functions -------------
#Call Create excel file function with one parameter to create CSV file 
$Excel_FilePath_WithExt = CreateExcelLogFile 'Output_CSV_FileName'

#Call write to excel function with 3 parameter to write in CSV file
Write-To-Excel-File $Excel_FilePath_WithExt "Son of Adam" "Addison"
Write-To-Excel-File $Excel_FilePath_WithExt "Man of Earth" "Adam"
Write-To-Excel-File $Excel_FilePath_WithExt "Father of Light" "Abner"

----------------------- Out put file in CSV format --------------
Output_CSV_FileName.csv

You can also see PowerShell to read rows from excel file

Ads