Thursday, 16 June 2016

Query Server Not Responding or Query Component Not Responding in SharePoint Search

Query Server Not Responding or Query Component Not Responding in SharePoint Search
Background : SharePoint Search new data is not getting crawled and the full & Increment crawling is never-ending.
Exception : Search Administration page
Propagation Status : Query server not responding(Guid – query-1)
Search Application Topology : Query Component Not Responding
Crawl Log :The server is unavailable and could not be accessed. The server is probably disconnected from the network.
Root Cause : When the query component is not responding then the SharePoint Search will not crawl the new content from the sites and it will not search the data from the new content sources created. Hence, the crawling status will not change.
Workaround : Before the general workarounds you can try different methods.
if you are fine with Search downtime and Index Reset, Please proceed with Method 1
Method 1 : Restart the Search Server Service
Restart the Search Server Service , Execute the below command on effected query server
stsadm -o osearch -action stop
stsadm -o osearch -action start -role query
if problem persists check the permissions of Index Folder, Ensure WSS_ADMIN_WPG, IIS_WPG has permission on this folder
You can find the location of index folder in Search Application Topology,Query Component>> Edit properties
General Location of Index. : C:\Program Files\Microsoft Office Servers\14.0\Data\Office Server\Applications
If the WSS_ADMIN_WPG, IIS_WPG don’t have read & execute access in Applications folder,Please grant read and execute permissions and check whether the issue resolves. If till issues persists please try Method 2
Method 2 : Change Index file Location
STSADM.exe –o osearch –propagationlocation “C:\NewLocationPath”
if the issue didn’t solve after executing the above command, please try Method 3
Method 3: Add a new query component
On the SharePoint Central Administration Web site, click General Application Settings and in the Search section click Farm Search Administration.
In the Search Service Applications section, from the list select the search service application that generated the event, and then click Modify Topology.
On the Topology for Search Service Application page, click the failed query component in the topology list, and then select Add Mirror from the component’s drop-list.
In the Add mirror query component dialog box, select the query server and associated metadata database for the new query component, and then click OK.
Click Apply Topology Changes. The changes are processed for the search application and the index is copied from the failed query component to the new query component.
Click the failed query component and click Delete.
The topology removes the index from the failed query component and deletes the component.
You can able to fix this issue using any one of above methods

Backup and Restore Site/Sub site list/document library in SharePoint

Backup and Restore Site/Sub site list/document library in SharePoint
Backup a sub site using power shell: Use export-spweb command to take sub site backup
Export-SPWeb -Identity "<subsite URL>" -Path "<directory\test.cmp>" -IncludeUserSecurity -IncludeVersions all
Restore a sub site using power shell: Use import-spweb command to restore sub site from backup
Import-SPWeb <subsite> URL -Path "<directory\test.cmp>" -Force -IncludeUserSecurity
------------------------------------------------------------------------------------------------------------------------------
Backup a List/Doc Library: use below export command to take list/doc library backup
Export-SPWeb -Identity <Site Collection URL> -Path <path and file name> -ItemURL "/Lists/list or Document library name" [-IncludeUserSecurity] [-IncludeVersions] [-NoFileCompression]
Restore a List/Doc Library: use below export command to restore list/doc library from backup

Import-SPWeb -Identity <Site Collection URL> -Path <path and file name> [-Force] [-NoFileCompression]

SQL querry to get the Database sizes

SQL query to get the Database sizes 
Use below SQL Script to get all DB sizes in MB
----------------------------------------------------------------------------------
SELECT d.name,
ROUND(SUM(mf.size) * 8 / 1024, 0) Size_MBs
FROM sys.master_files mf
INNER JOIN sys.databases d ON d.database_id = mf.database_id
WHERE d.database_id > 4 -- Skip system databases
GROUP BY d.name
ORDER BY d.name
-----------------------------------------------------------------------------------
You will get the .csv output by executing the query, the DB size will be in MB you can convert into GB

How to find SharePoint is connect SQL

How to find SharePoint is connect SQL
Use below Powershell command to check whether SharePoint is connected to SQL
Get-SPFarm
Use below Telnet command to check the connectivity between SharePoint and SQL
telnet {SQL-Server-Name or IP} 1433
Example: telnet mysharepoint 1433

PowerShell script to get site ID's in site collection

PowerShell script to get site ID's in site collection
‪#‎Script‬ to get site ID's in a site collection.
ADD-PSSnapin Microsoft.SharePoint.Powershell -erroraction silentlycontinue
Add-Type @'
public class SiteDetails
{
public string SiteId;
}
'@
$itemsColl = New-Object 'System.Collections.Generic.List[System.Object]';
‪#‎Site‬ URL
$siteurl=Read-Host "Enter Site URL"
$Site=Get-SPSite $siteurl
$spWebApp = $Site.WebApplication
foreach($allsites in $spWebApp.Sites)
{
$EvItem = New-Object SiteDetails
$EvItem.SiteId = $allsites.ID
$itemsColl.Add($EvItem);
}
$itemsColl | export-csv SiteReport.csv -noType

For more information about SharePoint visit MySharepoint

Making replica of a document library or list using SP designer

Making replica of a document library or list using SP designer

First create 2 document libraries to perform this operation, So just create Project Documents as a source document library & Shared Documents as a Destination document library

Step:1 Open site/site collection in SP designer















Step-2: Crete a Workflow in SP designer
In the left side panel click on “workflows” then select “list workflows”















Select Technology documents as a source document library












Enter the name as “File backup” click “OK”















Go to “Action” select Copy items



















Select to “which list” as “current item”







Select  “this list” as “Shared Documents”






After this click on “Save” and then click on “Check for errors”









Click on the workflows select “File backup” workflow






Check “Start automatically when an item is created” option then click om “Publish”



















Adding the documents to destination Document library & check for replica operation is working or not
Go to Technology Document library then add documents then wait for few minutes then check in Shared Document library the same documents you can find.

For more information about SharePoint visit MySharepoint

Basic Terms in SharePoint Search

Basic Terms in SharePoint Search
Search Topology
It is a combination of several topology components, all of which provide specific functionality required for Search to operate.
---------------------------------------------------------------------------------

What is crawling?
Crawling is the process that the SharePoint Server uses to access the data within the content source and build the search index.
Once a content source has been defined within the system, an administrator can define specific schedules by which the content will be crawled.
-----------------------------------------------------------------------------------
What is index?
An index is the location that contains details on all the information in the content sources. When users perform searches, the index is queried for content that matches the user-entered terms.
The index is comprised of both the metadata and content of the files contained within the system.
-----------------------------------------------------------------------------------
What is query?
When you conduct a search by entering a keyword or phrase into one of the available search boxes,you are creating a query.
This query will be performed against the content index to identify content that contains a match for a keyword or phrase that you have entered.
The search system will return a listing of items that match your query. These are referred to as search results.
-----------------------------------------------------------------------------------
How the Search Results work?
For the search you conducted, you entered a search query in the search box. The search query was conducted against the search index, and all SharePoint content that contained the term “sales”
was returned as part of the search results.

Wednesday, 15 June 2016

PowerShell Script to delete files/items in a document library/list folder structure will remain

PowerShell Script to delete files/items in a document library/list folder structure will remain

‪#‎Add‬-PSSnapin Microsoft.SharePoint.PowerShell
# Replace siteurl with actual web url
$web = Get-SPWeb -Identity "<Site/Site Collection URL>"
# Replace docurl with document library url
$list = $web.GetList("List/Document Library URL")
function DeleteFiles {
param($folderUrl)
$folder = $web.GetFolder($folderUrl)
foreach ($file in $folder.Files) {
# Delete file by deleting parent SPListItem
Write-Host("DELETED FILE: " + $file.name)
$list.Items.DeleteItemById($file.Item.Id)
}
}
# Delete root files
DeleteFiles($list.RootFolder.Url)
# Delete files in folders
foreach ($folder in $list.Folders) {
DeleteFiles($folder.Url)
}
==================================================
For more information about SharePoint visit page MySharepoint

Access Denied error in SharePoint

Issue: User getting "access denied" error even with sufficient group permission.
--------
Resolution:
----------------

Remove & re add the user to group by powershell.
stsadm -o adduser -url "<<Site URL>>" -userlogin "<<Domain\account>>" -group "<<SP Group>>"
Set-SPUser -Identity '<<Domain\account>>' -Web <<Site URL>> group "<<SP Group>>"

For more information about SharePoint visit page MySharepoint

PowerShell script to get the sites report under a site collection with size in MB

PowerShell script to get the sites report under a site collection with size in MB

# Returns size of site, subsites, folders, outputs in .\SiteSize.html
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
$rootUrl = "Site Collection URL";
$rootSite = new-object Microsoft.SharePoint.SPSite($rootUrl);
$array = @()
$siteCollectionSize = 0;
# Function calculating folder size
function GetFolderSize($folder)
{
$filesize = 0;
foreach ($file in $folder.Files)
{
$filesize += $file.TotalLength;
foreach ($fileVersion in $file.Versions)
{
$filesize += $fileVersion.Size;
}
}
foreach ($subfolder in $folder.SubFolders)
{
$filesize += GetFolderSize $subfolder
}
return $filesize;
}
# Function to format in MB
function FormatBytes ($bytes)
{
switch ($bytes)
{
{$bytes -ge 1TB} {"{0:n$sigDigits}" -f ($bytes/1TB) + " TB" ; break}
{$bytes -ge 1GB} {"{0:n$sigDigits}" -f ($bytes/1GB) + " GB" ; break}
{$bytes -ge 1MB} {"{0:n$sigDigits}" -f ($bytes/1MB) + " MB" ; break}
{$bytes -ge 1KB} {"{0:n$sigDigits}" -f ($bytes/1KB) + " KB" ; break}
Default { "{0:n$sigDigits}" -f $bytes + " Bytes" }
}
}
foreach($web in $rootSite.AllWebs)
{
if ($web.Url.StartsWith($rootUrl))
{
$websize = GetFolderSize $web.RootFolder;
foreach($recycleBinItem in $web.RecycleBin)
{
$websize += $recycleBinItem.Size;
}
$formatSize = FormatBytes $websize;
$url = $web.Url;
# Create object and store in array
$obj = New-Object System.Object
$obj | Add-Member -type NoteProperty -name "Description" -value "$url"
$obj | Add-Member -type NoteProperty -name "Size" -value "$formatSize"
$array += $obj
$siteCollectionSize += $websize
}
}
$formatSize = FormatBytes $siteCollectionSize;
# Create object and store in array
$obj = New-Object System.Object
$obj | Add-Member -type NoteProperty -name "Description" -value "[Total Size]"
$obj | Add-Member -type NoteProperty -name "Size" -value "[$formatSize]"
$array += $obj
# Display
foreach($item in $array)
{
write-output $item
}
# Write to HTML
$array | Select-Object | ConvertTo-Html -title "Site Size" | Set-Content .\SiteSize.html
====================================================================

For more information about SharePoint visit page MySharepoint

BLOB Cache in SharePoint

BLOB Cache in SharePoint:

A BLOB cache is a disk-based cache that stores binary large objects (BLOBs) such as frequently used image, audio, and video files, and other files that are used to display web pages. 
Each front-end web server maintains its own BLOB cache. When you enable a BLOB cache, you specify the file types to include in the cache and also the location of the BLOB cache. 
The first time that a BLOB file is requested, the file is copied from the database to the BLOB cache on the front-end web server. Future requests to the front-end web server for that same file are then served from the file that is stored in the BLOB cache, instead of being served from the database.
This reduces the network traffic and the load on the database server.
Configure BLOB cache settings:
By default, the disk-based BLOB cache is off and must be enabled on the front-end web server if you want to use it.
Steps:
1. Open IIS by goto run type "inetmgr" select the web site that you want to configure BLOB cache.








2. Right click select "Explore" then open the 














web.config file with notepad (Before making any changes to web.config file please make a copy)
3. find the following line: <BlobCache location="C:\BLOB\14" path="\.(gif|jpg|jpeg|jpe|jfif|bmp|dib|tif|tiff|themedbmp|themedcss|themedgif|themedjpg|themedpng|ico|png|wdp|hdp|css|js|asf|avi|flv|m4v|mov|mp3|mp4|mpeg|mpg|rm|rmvb|wma|wmv|ogg|ogv|oga|webm|xap)$" maxSize="10" enabled="false" />




4. In this line, change the location attribute to specify a directory that has enough space to accommodate the cache size.
5. To add or remove file types from the list of file types to be cached, for the path attribute, modify the regular expression to include or remove the appropriate file extension.
6. To change the size of the cache, type a new number for maxSize. The size is expressed in gigabytes (GB), and 10 GB is the default.
7. To enable the BLOB cache, change the enabled attribute, from "false" to "true" and save the notepad.
--------------------------------------------------------------------------------------------------------------------------------
Flush the BLOB cache:
====================
When you flush the BLOB cache, you clear the contents of the BLOB cache for a web application. This is useful if the BLOB cache becomes out of sync with the content.
(Note: You cannot use the user interface to flush the BLOB cache. Instead, you use Windows PowerShell and the SharePoint object model to complete this task.)
1. Verify that you have the following memberships:
- securityadmin fixed server role on the SQL Server instance.
- db_owner fixed database role on all databases that are to be updated.
- Administrators group on the server on which you are running Windows PowerShell cmdlets.
2.Copy the following code and paste it into a text editor, such as Notepad.
$webApp = Get-SPWebApplication "<WebApplicationURL>"
[Microsoft.SharePoint.Publishing.PublishingCache]::FlushBlobCache($webApp)
Write-Host "Flushed the BLOB cache for:" $webApp
(Replace <WebApplicationURL> with the URL of the web application whose BLOB cache you want to clear)
3.Save the file, and name it FlushBLOBCache.ps1 and then run.

For more information about SharePoint visit page MySharepoint

PowerShell script to empty first level & Secondary level recycle bin in SharePoint

PowerShell script to empty first level & Secondary level recycle bin in SharePoint
$sitecollectionUrl = “<Site Collection URL>”
$siteCollection = New-Object Microsoft.SharePoint.SPSite($sitecollectionUrl)
write-host(“Items to be deleted : ” +$siteCollection.RecycleBin.Count.toString())
#$now = Get-Date
‪#‎write‬-host(“Deleting started at ” +$now.toString())
$siteCollection.RecycleBin.DeleteAll();
#$now = Get-Date
#write-host(“Deleting completed at ” +$now.toString())
$siteCollection.Dispose();
===========================================
If you run First time it will remove items on second level recycle bin and move the files from first level recyclebin to second level.
If you run second time files will delete from second level. 
Visit Facebook page for more scripts and details MySharepoint
Enjoy 

Enabling Verbose in SharePoint

Enabling Verbose in SharePoint
----------------------------------------------
We can enable the verbose in SharePoint using PowerShell and Central Administration

Using PowerShell commands to enable and disable verbose

For better practice use below command to generate new log file then enable verbose.
Step-1: go to SharePoint products and select “Management shell
Open Management shell as “Administrator” and type New-SpLogFile





Step-2: Set log level to verbose
Set-SPLogLevel -TraceSeverity Verbose -EventSeverty Verbose






Step-3: Set log level back to default (After recreating the issue and collecting the logs set the log level back to default)
Set-SPLogLevel -TraceSeverity Medium
or 
Get-SPLogLevel | Clear-SPLogLevel






Using Central Admin to enable and disable verbose

1) Open your Central Administration

2) Click Monitoring and Click “Configure Diagnostic Logging”















3) Select “All Categories” and














Select “Verbose” for “Least critical event to report to the event log”

Select “Verbose” for “Least critical event to report to the event log”
















4) Click "Ok".

5) After recreating the issue and collecting the logs set the log level back to default as mentioned below

Select “Reset to default” for “Least critical event to report to the event log”
Select “Reset to default” for “Least critical event to report to the trace log”