Ads

Tuesday, 15 May 2018

Steps to consume user profile from different sharepoint farm

Step 1. Set up the Application Discovery and Load Balancer Service Application

Before any farm can provide services to another farm, the consuming farm must be able to use the Application Discovery and Load Balancer Service. This is also known as the Topology Service. The part we are concerned with here is the Application Discovery piece. The consumer needs rights to use the service so that it can find the proxies on the publishing farm. To do this you need to follow these steps.
1.      On the Consumer farm.
a.      Open up SharePoint 2010 Management Shell
b.      Type in (Get-SPFarm).Id
c.      Copy the output to notepad (or just keep it open so you can type it in)
2.      On the Publishing farm.
a.      Open up SharePoint 2010 Management Shell
b.      Type in $security = Get-SPTopologyServiceApplication | Get-SPServiceApplicationSecurity
c.      Then type $claimProvider = (Get-SPClaimProvider System).ClaimProvider
d.      Then type $principal = New-SPClaimsPrincipal -ClaimType "http://schemas.microsoft.com/sharepoint/2009/08/claims/farmid" -ClaimProvider $claimProvider -ClaimValue paste the farm id from step 1 here just as it appeared
e.      Then type Grant-SPObjectSecurity -Identity $security -Principal $principal -Rights "Full Control"
f.       Then type Get-SPTopologyServiceApplication | Set-SPServiceApplicationSecurity -ObjectSecurity $security


Step 2. Create your certificates. You need to exchange certificates between servers. The consumer will need the Root certificate of the publishing farm, but the publishing farm will need the Root certificate of the consumer and the STS (Security Token Service) certificate. You can go to the TechNet article here http://technet.microsoft.com/en-us/library/ee704552.aspx or follow these steps.
1.      On the consumer farm
a.      Open up SharePoint 2010 Management Shell
b.      Type  $rootCert = (Get-SPCertificateAuthority).RootCertificate
c.      Then Type $rootCert.Export("Cert") | Set-Content C:\ConsumingFarmRoot.cer -Encoding byte
d.      You now have the root certificate for the consuming server on the C drive of the consuming server. Next we get the STS certificate.
e.      Type $stsCert = (Get-SPSecurityTokenServiceConfig).LocalLoginProvider.SigningCertificate
f.       Then Type $stsCert.Export("Cert") | Set-Content C:\ConsumingFarmSTS.cer -Encoding byte
g.      You now have the STS Token for the consuming farm.
h.      Make the two files you created available to the publishing farm (i.e. copy them to the publishing farm)
2.      On the publishing farm.
a.      Open up SharePoint 2010 Management Shell
b.      Type  $rootCert = (Get-SPCertificateAuthority).RootCertificate
c.      Then Type $rootCert.Export("Cert") | Set-Content <C:\PublishingFarmRoot.cer> -Encoding byte
d.      Make the file available on the consuming farm.

Step 3. Import the certificates.
1.      Import the consumer root certificates on the publishing server.
a.      Open up SharePoint 2010 Management Shell on the publishing server
b.      Type $trustCert = Get-PfxCertificate C:\ConsumingFarmRoot.cer (replace c:\publishingfarmroot.cer with the location of the consuming server root cert)
c.      Then Type New-SPTrustedRootAuthority type the name of the consuming server here  -Certificate $trustCert
d.      The certificate should print to the screen if it was successful
2.  Import the consumer STS certificate on the publishing server
a.      Open up SharePoint 2010 Management Shell on the publishing server
b.      Type $stsCert = Get-PfxCertificate c:\ConsumingFarmSTS.cer (replace c:\consumingfarmsts.cer with location of consuming server STS cert)
c.      Then type New-SPTrustedServiceTokenIssuer type the name of consuming server -Certificate $stsCert
d.      The certificate should print to the screen if it was successful
3.  Import the publishing root certificate on the consuming server
a.      Open up SharePoint 2010 Management Shell on the consuming server
b.      Type $trustCert = Get-PfxCertificate C:\PublishingFarmRoot.cer (replace c:\publishingfarmroot.cer with the location of the publishing farm root cert)
c.      The certificate should print to the screen if it was successful

Step 3. Publish the service. You have to publish the service from the publishing server before it can be consumed. The easiest way to do this is from Central Administration
1.      Navigate to the central administration of the publishing server.
2.      Click on Manage service applications
3.      Click on the User Profile Service (off to the right of it. You don’t want to manage it just highlight it)
4.      Click on the Publish icon at the top of the page.
5.      Make sure the Publish this Service Application to other farms is checked.
6.      Copy the Published URL. It is a really long thing that looks similar to this urn:schemas-microsoft-com:sharepoint:service:6f63cdec5e784a02b2b79f9bf91346af#authority=urn:uuid:daf0ec20a27a44c7abe5104b5d516637&authority=https://orsps01:32844/Topology/topology.svc 
7.      Click OK. You are done with the publishing server now.
Step 4. Consume the service.
1.      Open up the Central Administration of the consuming server.
2.      Click on Manage service applications
3.      Click on the Connect icon on the top ribbon and choose User Profile Service Application Proxy
4.      In the Connect to a Remote Service Application dialog paste the Url from Step 3 (yours, not the example above)
5.      Click OK. You should see a screen that shows the connection (or an error page if it didn’t)
6.      Highlight User Profile Service and click OK.
7.      You should get a confirmation screen and click OK again.
You have now consumed the User Profile Service. That means when a user updates their profile data it will be the same on both farms. It will use the trusted My Site locations, the audiences, etc. from the publishing farm. Therefore if you want to add/modify anything  for the consumer farm it needs to be done on the central administration of the publishing farm.
Share service applications across farms in SharePoint Server

Friday, 4 May 2018

Powershell to add user in Sharepoint group




Below is the PS commands to give permission to user in any SharePoint site in any SharePoint group

Here I have added my account(RR) to group “test 222 Owners” of site collection https://***/sites/test_222/
  • Replace https://***/sites/test_222/  with Site collection URL   
  • Replace test 222 Owners with group name
  • Replace RR  with User Signum.

So use above work around to resolve individual’s incident related  to access issue or add user incidents in Ericoll extranet site.

$SiteCollection = Get-SPSite “https://***/sites/test_222/
$Rootweb = $SiteCollection.RootWeb
$NewExtranetUser = New-SPUser -UserAlias "i:0#.w|ericsson\RR"
                Web  "https://***/sites/test_222/"  <Above command will ask for web value so give your site collection URL>

$SharePointGroup = Rootweb.SiteGroups["test 222 Owners"]
Set-SPUser -Identity $NewExtranetUser -Web Rootweb -Group $SharePointGroup


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

Tuesday, 28 March 2017

Powershell script to read CSV file to do any automation

Lets we have one csv file with column SiteUrl. Below is the script which will read from csv file
 
 
# Power shell Read the rows from CSV file   

$CSVFile = Import-CSV -path "C:\DataHere.csv"  

foreach($row in $CSVFile)
{ 
    write-host "Read Site " + $row.SiteUrl        
    Write-host ""
    Write-host "Pausing for 200 seconds..."
    Sleep 200
} 

----------------------- or --------------

Here we are dismounting DBs by reading from CSV file as shown here


Import-CSV C:\DataHere.csv -Header Server, DatabaseName | Foreach-Object{
   if($_.DatabaseName -ne "DatabaseName")
   {       
        Dismount-SPContentDatabase $_.DatabaseName.Trim() -confirm:$false       
   }  
}


Ads