Monday, December 31, 2012

Find Active Inactive Site Collections in SharePoint

Some time back, wrote a PowerShell script to find Most active sites(sub-sites) in SharePoint: Find Most Active SharePoint Sites of a Web Application. Now have a similar requirement, but for SharePoint Site collection! Find Active and Inactive SharePoint site collections of a project collaboration environment.

How to find Most Active SharePoint Site Collections? 
Well, SPSite object has LastContentModifiedDate property, why don't we use it? Here is the nifty PowerShell script to find Most active Site collections based on content modified date. In a reverse, this can be used to find all In-active site collections also.

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
 
Get-SPWebApplication "https://sharepoint.company.com" | Get-SPSite -Limit All | foreach {
Write-Host $_.URL  $_.LastContentModifiedDate
}

This will reveal SharePoint 2010 inactive sites. For SharePoint 2007, you can slightly change the code.

BTW, I use PowerGUI IDE for writing and debugging PowerShell scripts! as it supports IntelliSense, Debugging and much more.
SharePoint find Most Active Inactive Site collections


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Hide Columns in SharePoint List NewForm, EditForm and DispForms

Had a requirement to hide a specific column "Parent Project" in a SharePoint list "Project Metrics", Since this field was being updated by an internal workflow, it must not be visible in NewForm or in EditForm.

So to protect a particular column from edits, decided to hide it from New & Display Forms. Here are the various methods I've used in different scenarios.

SharePoint SPField Object has the following properties to control its visibility.
  •     ShowInNewForm - Show in the list settings page
  •     ShowInEditForm - Controls field in edit form page
  •     ShowInDisplayForm -Show in the display form page.
  •     ShowInListSettings - Show in the list settings page
  •     ShowInViewForms -Show field in views field selection
  •     ShowInVersionHistory - Show in the version history view
These field properties are self-explaining, isn't it? Lets see various ways to Hide SharePoint List Columns.

Enable Content Type and Hide the Field:
This will hide the field from All list forms - NewForm, EditForm and DispForm.
  • Go to List Settings and enable content type by clicking "Advanced settings" and then choose "Yes" for "Allow management of content types?".
  • Once done, You see "Content Types" in list settings. Click on "Item" link.sharepoint hide field
  • Select the Field to hide
    sharepoint hide columns on form
  • Choose "Hidden" under column settings.
sharepoint hide column in list
This will hide the selected field from ALL List forms (NewForm, EditForm and DispForms).

Using SharePoint Manager Tool to Hide SharePoint List Form Fields:
My favorite utility, SharePoint Manager is not just a Object Explorer but supports changing configurations also. So we can use SharePoint Manager to change the specific fields properties. Just download the SharePoint Manager, navigate to the field all the way through Web Applications, Site Collections, Sites, Lists. Set the "ShowInDisplayForm" or whatever required and save the changes.
sharepoint list hide a columnm with SharePoint Manager

PowerShell Script to Hide SharePoint List Columns:
SharePoint fields can be hidden programmatically. Why not PowerShell? Lets use PowerShell to set the field properties.
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
#Get the Web
$SPWeb = Get-SPWeb "http://sharepoint.crescent.com"
#Get the List
$SPList = $SPWeb.Lists["Project Matrics"]
#Get the Field
$SPField = $SPList.Fields["Parent Project"] 

#Hide from NewForm & EditForm
$SPField.ShowInEditForm = $true
$SPField.ShowInNewForm  = $false

$SPField.Update()
$SPWeb.Dispose()

Same code goes in MOSS 2007 also, with slight change to hide list field in SharePoint 2007:
 [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")

  $SPSite = New-Object Microsoft.SharePoint.SPSite("http://sharepoint.crescent.com")
  $SPWeb = $SPSite.OpenWeb()

  $SPList = $SPWeb.Lists["Project Matrics"]

  $SPField = $SPList.Fields["Parent Project"]
  $SPField.ShowInNewForm = $False
  $SPField.ShowInEditForm = $False
  $SPField.Update()

  $SPSite.Dispose()

Object Model C# Code to hide fields on a form:
       using (SPSite oSPSite = new SPSite("http://sharepoint.crescent.com"))
            {
                using (SPWeb oSPWeb = oSPSite.OpenWeb())
                {
                     //Get List & Field
                    SPList oSPList = oSPWeb.Lists["Project Metrics"];
                    SPField oSPField = oSPList.Fields["Parent Project"];

                    oSPField.ShowInEditForm = true;
                    oSPField.ShowInNewForm  = true;

                    oSPField.Update();

                }
            }

 Before hide column from SharePoint list: Parent Project
sharepoint list hide a column
 After hiding column from list form page:
sharepoint 2010 hide list column

Using JavaScript to Hide Form Fields:
Just edit the List form page by appending ?toolpaneview=2 at the end. Add a CEWP to the page, place this JavaScript code: (Its not written by me, BTW!)
<script language="javascript" type="text/javascript">
_spBodyOnLoadFunctionNames.push("HideColumns");

function GetControl(FieldName) 
{
   var arr = document.getElementsByTagName("!");

   for (var i=0;i < arr.length; i++ )
   {
      if (arr[i].innerHTML.indexOf(FieldName) > 0) {
          return arr[i];     
      }
   }
}

function HideColumns()
{
   var control = GetControl("Parent Project");
   control.parentNode.parentNode.style.display="none";
}
</script>

Hide SharePoint list column with jQuery: This can be done using jQuery as well. Here is my post on How to hide SharePoint list form field using jQuery

Do not hide a required field, or else you will not be able to Save list item!
Another alternate would be editing the Form page in SharePoint designer and set "Hidden" property for relevant field, or even conditional format to hide a filed also will work.

There is a project in Codeplex: Office Toolbox, provides interface for hiding SharePoint list columns/fields from interface. Check it out!

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Thursday, December 27, 2012

Create Send To Connection with PowerShell

In continuation to my post: SharePoint 2010 Configure Send To Connections , If you want to create send to connections programmatically or have multiple send to connections to create, PowerShell can help to automate it:

PowerShell Script to Create Send To Connections:

#Get the Web Application
$WebApp = Get-SPWebApplication "http://sharepoint.crescent.com"

$SPOfficialFileHost = New-Object Microsoft.SharePoint.SPOfficialFileHost
#Set Send to Options#
#Send to Connection Name
$SPOfficialFileHost.OfficialFileName = "Project Directory"
#Send to Target location
$SPOfficialFileHost.OfficialFileUrl = "http://sharepoint.crescent.com/teams/PMO/ProjectDir/_vti_bin/officialfile.asmx"
$SPOfficialFileHost.ShowOnSendToMenu = $true
#Send to Operation
$SPOfficialFileHost.Action=[Microsoft.SharePoint.SPOfficialFileAction]::Copy
$SPOfficialFileHost.Explanation = "Send to connection for Project submission"
$WebApp.OfficialFileHosts.Add($SPOfficialFileHost); 
$WebApp.Update()
 
Make sure you activated "Content Organizer" in Send To Target site before proceeding!

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Wednesday, December 26, 2012

SharePoint 2010 Configure Send To Connections

In my organization, Program Managers group from multiple departments wanted to collect documents from their department sites to a centralized location for brainstorming. Somehow they heard about/located send to connections in SharePoint!

What is Send to connections in SharePoint?
Send to connections in SharePoint is a great and flexible way to manage documents. Users can easily Move or Copy document to a new location. Documents can be sent across sites, site collections and even web application. Its often used with records center, But we can enable "Content Organizer" feature to activate Custom Send To connections on any site. Lets see how to configure Send To connections in SharePoint 2010.

Steps to Create New Send to Connection:
  1. Activate Content Organizer in Target site where you want your documents to be collected.
  2. Create a Custom Send To connection in Central Administration
  3. Copy/Move documents by clicking "Send To >> Send to Location"
Step 1: Activate Content Organizer in Target site

Before proceeding with further steps, You must activate "Content Organizer" in target site where you want your documents to be collected. or you will get an error message when you try to create a new send to connection.
sharepoint send to feature
If you don't activate, You will get this error during send to connection creation in Central Administration!
sharepoint 2010 send to not working

Step 2: Create a Custom Send To connection in Central Administration
  • Go to: Central Administration >> General Application Settings >> Click Configure send to connections under External Service Connections.
sharepoint send to custom location
  • Select the web application,  Allow manual submission from the Send To menu ,0Provide a Name for your custom send to connection,  and Most importantly, Provide the Send To URL:
sharepoint 2010 configure send to connections

  • Verify the Send to URL by clicking "Click here to test"
sharepoint send to destination
  • Allow manual submission from the Send To menu, Select "Copy" action.
  • In addition to copy documents, you can also choose to move &  move a document and leave a Link in the current document library location that points to the new location of the document. 
  • Finally, click on "Add Connection" to create new send to connection.

How to get SharePoint 2010 send to URL?
A typical Send to URL would be: http://sharepoint.com/<Site-collection>/<sub-Site>/_vti_bin/officialfile.asmx. You can get the Send to URL by going to the target site's settings >> Content Organizer Settings
sharepoint send to another site collection
scroll down and make a note of Web Service URL under "Submission Points" column.
sharepoint 2010 send to url

Step 3: Copy/Move documents by clicking "Send To >> Send to Location"
Once Send To Connection is created, you should should see it in the item context menu in the "Send To" category. "Send To" locations are applied to all documents in the web application. Go to any document library, from items context menu (ECB Menu) click on "Send To" and you can find your custom send to connection there.
 sharepoint 2010 configure send to connections
When you click on "send to" and your send to location, you will be prompted to confirm your submission. Once you click "Ok"
 sharepoint 2010 send to connections
The content organizer rule will apply and route the document to the right destination library.


Where All documents will go when I click on "Send to"?
They'll go and sit inside "Drop-off" Library of the site. It can be further customized with content organizer rules.
sharepoint send to another site collection


Send to connections between web applications
When you configure send to connections between web applications, make sure your source web application's application pool account is in "Configure a group Records Center Web Service Submitters for <Site Name>" group under site permissions. SharePoint will error : The site could not be found or accessed, If you don't do the above step!

SharePoint send to permissions required:
 sharepoint 2010 send to Permissions
Configure Send To Connection with SSL
If you are configuring send to connections in SSL sites, You have to establish a Trust. Here is hot: Navigate to CA>> Security >> General Security >>Manage trust >> Create a New Trust Relationship. In "Trust Relationship" browse and locate the root authority certificate of the website (The issuer of SSL certificate). You can Ignore values for "Provide Trust Relationship"


Tail:
If Send To connection results, HTTP status 401: Unauthorized, It could be because of LoopBackCheck. Just disable it! 401 unauthorized issue in SharePoint - DisableLoopbackCheck

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Update a Column Value for All List Items in SharePoint using PowerShell

Requirement is to update a list item in SharePoint using PowerShell. Here are some code scripts to update SharePoint list item using PowerShell script.

PowerShell to update a column value for all List items in SharePoint
The syntax for updating a specific column value on SharePoint List item goes like this:
$Web = Get-SPWeb "http://sharepoint-site-url"
$List = $web.Lists["List Name"]

foreach ($item in $list.Items)
{
  $item["ColumnName"] = "New value"
  $item.Update()
}
This PowerShell updates all list items in SharePoint. Here is an example for update all items in a SharePoint list with PowerShell:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
#Get the List
$Web = Get-SPWeb "http://intranet.crescent.com"
$List = $web.Lists["Contacts"]

#Get all List Items
$ListItems = $List.Items

#if the Item Found
foreach($Item in $ListItems)
{
    #Update 'Company' Field Value
    $Item["Company"] = "Crescent Inc."
    $Item.Update()
} 

SharePoint PowerShell update list item by id:
Lets pick a specific list item from its ID and update it.
 
#Get the List
$Web = Get-SPWeb "http://intranet.crescent.com"
$List = $web.Lists["Contacts"]

#Get the List Item from Its ID
$ListItem = $List.GetItemById("1")

#Update 'Last Name' Column
$ListItem["Last Name"] = "Thomas Cook"
$ListItem.Update()

Update list item SharePoint 2010 using PowerShell
This script picks a list item using its field value and updates it using PowerShell.
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Get the List
$Web = Get-SPWeb "http://intranet.crescent.com"
$List = $web.Lists["Contacts"]

#Get the List Item from column value
$ListItem = $List.Items | Where { $_["Last Name"] -eq "Thomas" }

#if the Item Found
if($ListItem)
{
    #Update 'Last Name' Column
    $ListItem["Last Name"] = "Thomas Cook"
    $ListItem.Update()
}


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Copy SharePoint List or Library between Sites with PowerShell

In a migration project, we had to move few lists and libraries to different site collection. In SharePoint 2010, using granular export, we can export SharePoint lists and libraries from one site to another with SharePoint Central Administration web interface.
copy sharepoint 2010 list between sites
Once exported we've to use Import-SPSite PowerShell cmdlet to restore the list. Lists can be copied to different SharePoint site as well.
copy sharepoint list another site
Exporting from Central Admin UI and importing it again isn’t that much great time saver, So lets turn our attention to PowerShell to copy SharePoint 2010 list between sites. Here is my PowerShell script to Copy a single List or Library to another SharePoint Site:

Export Import a Library using PowerShell:
Export-SPWeb "http://your-site-url" -itemurl "/document" -path "c:\documents.cmp" -IncludeVersions All

Import-SPWeb "http://your-new-site-url/" -Path "c:\documents.cmp"

PowerShell Script to Backup-Restore (Or Export-Import) SharePoint List:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Function to copy List or Library from One SharePoint site to another 
Function CopyList([string]$SourceWebURL, [string]$TargetWebURL, [string]$ListName, [string]$BackupPath)
 {
    #Get the Source List
    $SourceList =(Get-SPWeb $SourceWebURL).Lists[$ListName]

    #Export the List from Source web
    Export-SPweb $SourceWebURL -ItemUrl $SourceList.DefaultViewUrl -IncludeUserSecurity -IncludeVersions All -path ($BackupPath + $ListName + ".cmp") -nologfile

   #Import the List to Target Web
    import-spweb $TargetWebURL -IncludeUserSecurity -path ($BackupPath + $ListName + ".cmp") -nologfile
 }
#Call the function
CopyList "http://sharepoint.crescent.com" "http://sharepoint.crescent.com/teams/marketing" "Banner" "C:\Temp\"

When I had a bunch of Lists to move from one site to another, I Just placed them in an array and called the function like this:

$Lists = @("Project Docs", "Project Metrics", "Milestones")

 foreach($List in $Lists)
 {
   #Call the function to copy
   CopyList "http://sharepoint.crescent.com" "http://sharepoint.crescent.com/teams/marketing" $List "C:\Temp\"
 }
 
 Write-Host "Completed!"

In an another situation, I had to copy of all Lists and libraries from a one Site Collection to another Site Collection. To export a single list use:
Export-SPweb "https://portal.crescent.com/News" -ItemUrl "Lists/Org News" -IncludeUserSecurity -IncludeVersions All -path "C:\Reports\News.cmp" -nologfile

PowerShell Script to Copy All Lists from One site to Another
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Function to copy List or Library from One SharePoint site to another 
Function CopyList([string]$SourceWebURL, [string]$TargetWebURL, [string]$ListName, [string]$BackupPath)
 {
    #Get the Source List
 $SourceList =(Get-SPWeb $SourceWebURL).Lists[$ListName]

   #Export the List from Source web
    Export-SPweb $SourceWebURL -ItemUrl $SourceList.DefaultViewUrl -IncludeUserSecurity -IncludeVersions All -path ($BackupPath + $ListName + ".cmp") -nologfile -Force

   #Import the List to Target Web
    import-spweb $TargetWebURL -IncludeUserSecurity -path ($BackupPath + $ListName + ".cmp") -nologfile -UpdateVersions Overwrite
 }
  
#Get All List Names
$Lists = @($(Get-SPWeb $SourceWebURL).lists)

 foreach($List in $Lists)
 {
  #Leave the Hidden Lists and exclude certain Libraries
    if($List.Hidden -eq $false -and $List.Title -ne "Style Library" -and $List.Title -ne "Site Pages")
 {
     #Call the function to copy
     CopyList "http://sharepoint.crescent.com" "http://sharepoint.crescent.com/HR/" $List.Title "C:\Temp\"
    }
 }
Write-Host "Completed Copying Lists!"
These scripts copies SharePoint list to another site including security and versions. Saving list as template with content, Export to spreadsheet are the OOTB methods for copying lists between site collections.

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Wednesday, December 12, 2012

Rotating Banner for SharePoint using jQuery

With jQuery we can do lot of user interface enhancements in SharePoint. In this article, I'm exploring one of them: Add rotating banner for SharePoint using jQuery, Let our SharePoint site display moving top banner. Lets start building rotating banner for SharePoint!

jQuery Rotating Banner for SharePoint - Steps in Brief:
Here is how to create rotating banner in SharePoint
  1. Download and create necessary files
  2. Create the folder structure as explained below
  3. Create HTM file for banner Rotator. Update the links to point to your SharePoint site for images and JavaScript files in HTM and CSS.
  4. Add a Content Editor web part to the page, specify the banner HTM file.
Step 1: Download and create necessary Files
For SharePoint scrolling banner implementation, we need below files:
  1. jquery.min.js - Get it from: https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js
  2. jquery.cycle.all.js - http://cdn.jsdelivr.net/cycle/2.9999.6/jquery.cycle.all.js
  3. A CSS file to define styles for our rotating banner
  4. Banner images, and rotator control images (like Previous, Next, switch.)
  5. A HTML page which has rotating banner code!
for the last CSS and HTM files, You can refer: http://malsup.com/jquery/cycle/more.html?v2.23

Step 2: Create the Folder Structure
Head on to your SharePoint site, Create a Asset library (or even document library will do!) and create 3 sub folders:
  • A Folder for rotating banner scripts, say "scripts"
  • A Folder for Images, say "images"
  • and a folder for CSS Styles, say "styles"
So, Your Library and folder structure will look like:
jquery rotating banner sharepoint
Create a HTM and CSS file (You can refer online demos of the provides links)
Create a HTM file and CSS file from the content provided below. 

CSS File Content: say, Slider.css 

HTML File Conent: say, Banner.htm 
SharePoint 2010 JQuery Banner

Images: (6 Images)
create rotating banner sharepoint

add rotating banner sharepoint 2010

sharepoint 2007 rotating banner

rotating banner for sharepoint

 rotating banner sharepoint web part

SharePoint banner rotator





Download and upload these images to your SharePoint Library's images folder.

Step 3: Update the links in HTM and CSS files
Update the Links for Images, JavaScript files in HTM and CSS files.

Here is my scripts folder:

rotating banner script sharepoint
Here is my Images folder:
add rotating banner sharepoint
and the styles folder:
sharepoint 2010 rotating banner

Upload the files to relevant folders.

Add a Content Editor web part to the page, specify the banner html file.
sharepoint rotating banner web part
See Rotating banner for SharePoint 2010 using jQuery in action!
sharepoint rotating banner
Although, The above implementation talks about implementing jQuery Rotating banner for SharePoint 2010, it can be used in SharePoint 2007 or any of the web sites. It can be placed in master page even.

Download all Scripts/Images/Code for this banner:
You can download the source code for jQuery banner rotator for SharePoint with scripts, images and CSS, here: Rotating Banner for SharePoint using jQuery. Don't forget to update the Links for Images, JavaScript files in HTM and CSS files.

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Monday, December 10, 2012

Set SharePoint Web Application or Farm to Read Only Mode

During maintenance/migrations, its inevitable to set the entire SharePoint Farm or at least Web Applications to read-only mode for some time. SharePoint doesn't provide any direct ways to set the entire web application or Farm to Read-only mode, but we've these options available to set read only access to either SharePoint Web Application or Farm.
  1. Using Central Administration user permissions
  2. Set read-only mode for all site collections of the web application through PowerShell
  3. Set all SharePoint content databases of the web application to read-only mode

Option 1: Using Central Administration User Permissions to Make SharePoint web application read only:
Go to Central Administration >> Application Management >> Manage web Applications >> and select "User Permissions"
sharepoint web application read only
Un-check "Select All" and Select Permissions which are starting with "Open, View, Browse". such as: View Items, Open Items, Browse User Information.
sharepoint 2010 web application read only
This will make the selected web application to read-only.

Option 2: Set read-only mode for all site collections of the web application through PowerShell To set SharePoint 2010 web application read only
Using SharePoint Central Administration, We can Set the lock for a particular site collection, which is straight forward. Since, Its possible to set the site collection to read-only mode using PowerShell, We can loop through the each and every site collection in the web application and set the site collection's status to read-only. Once done with the migration/maintenance, you can unlock the sites again.

# Get the Web Application
$WebApp=Get-SPWebApplication "http://SharePoint.company.com"

#Loop through all site collections and Set read only status
    foreach ($SPsite in $webApp.Sites)
    {
       $SPsite.ReadOnly = $true
       #Or you can use: Set-SPSiteAdministration -LockState "Unlock" -Identity $SPsite.url
    }

For More info on Site collection locks, refer my post: Site Collection Locks in SharePoint

Option 3. Set all SharePoint content databases of the web application to read-only mode
Get the Content Databases Associated with the web application:
Go to Central Administration >> Application Management >> Manage Content Databases
Select the desired web application and make a note of all content databases.
make sharepoint farm read-only
or you can use the PowerShell one liner to retrieve all content databases of the web application:
Get-SPContentDatabase -WebApplication "http://SharePoint.company.com" | Select Name
You can repeat it for all web application to make entire SharePoint 2007 to SharePoint 2010 farm read only.

Make web app read only by setting all content databases to read only Mode

To set content databases to be read-only using SQL Server Management Studio:
  1.     Open SQL Server Management Studio.
  2.     Right-click the SharePoint content database and click Properties.
  3.     Go to Options tab and in the Other options list, scroll to the State section.
  4.     Set the Database Read-Only row to True, and then click OK.
  5.     Repeat this for all content databases of the web application
sharepoint 2010 or sharepoint 2007 web application read only
You can do this for all web applications to make SharePoint farm read-only.


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


SharePoint 2010 Search Error: The search request was unable to connect to the Search Service.

After configuring SharePoint search service application, Got this error message when I attempt to do a search: "The search request was unable to connect to the Search Service"
The search request was unable to connect to the Search Service

I verified search settings, crawl logs and found they are fine. After a while nailed the issue: Search Service proxy association. Fix is simple:


Go to Central Administration >> Manage Web Applications >> Selected your target web application
SharePoint 2010 Web Application Service Connection
Click Service Connections from the ribbon. This will list all connections. Found the search service "Search Service Application " and was not connected to our web application!
SharePoint service application association

Just ticked the  search service application we configured and we are back to business!


Other Reasons:
Apart from Search service proxy association, There could be many other reasons for this error message:
1. Make sure you have the search service application created, up and running. If not, create a new search service application.


2. SharePoint Server Search Service may be in stopped state. Go to Services console (services.msc) Make sure "SharePoint Server Search 14" is started. If not just start/restart it.

For MOSS 2007, start these search services: Office SharePoint Server Search, Windows SharePoint Services Search.

3. Applicable to MOSS 2007: The SharePoint Server may not be configured to serve search queries
  •     Go to Central Admin
  •     Operations
  •     Services on Server
  •     Office SharePoint Server Search Service Setting
  •     Check "Use this server for serving search queries" check-box.
4. Search content access account might not have enough access rights. Grant read access on Search content access account to the target web application using web application policy.

5. This may due wrong settings in search Core Results web part. Fix or replace it.

6. Make sure the Ports  TCP/UDP 445, 56737 & 56738 in which SharePoint Index & Query servers communicate is open.

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Sunday, December 9, 2012

Configure Diagnostic Logging in SharePoint 2010 - Best Practices, FAQs

What is Diagnostic Logging in SharePoint, By the way?
Simple! Diagnostic logging is where SharePoint logs it's own actions. There are two log file locations where SharePoint Diagnostic logging keeps its logs:
  1. Windows Event Log - You can view it with "Event Viewer" - The one comes with Windows!disable diagnostic logging sharepoint 2010
  2. ULS or "Trace Log" - Text based log format that is specific to SharePoint Server and is stored on the file system. The default location is  C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\LOGS
ULS loges are following the naming convention of  "ServerName-YYYYMMDD-HHMM" and each subsequent file is created in 30 minutes intervals by default. Look at the below screenshot.
enable diagnostic logging sharepoint 2010

Where to Configure Diagnostic Logging?
Go to Share 2010 Central Administration >> Monitoring >> Click "Configure diagnostic logging" (Under Reporting)
sharepoint 2010 configure diagnostic logging settings

From Here you can select the Category,  Least critical event to report to the event log,  Least critical event to report to the trace log. sharepoint 2010 diagnostic logging best practices

SharePoint 2010 configure diagnostic logging settings best practices

No doubts! enabling SharePoint diagnostic logging is very important and helpful. However, it could cause performance issues and slows down SharePoint if not managed properly!! Follow best practices on SharePoint 2010 powershell diagnostic logging:

1. Change the Log file Path - For performance reasons, Don't keep the log files on the same drive where SharePoint installed. By default SharePoint diagnostic logging path is set to %CommonProgramFiles%\Microsoft Shared\Web Server Extensions\14\LOGS\  (which is: C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\LOGS). Change it to some other drive! This can be done with  PowerShell cmdlet:
Set-SPDiagnosticConfig -LogLocation <PathToNewLocation>

2. Ensure you Restrict Trace Log disk space usage  - You don't want SharePoint to fill your c:\ with logs, isn't it? so be watchful. These two cmdlets can be used to configure disk space usage.

Set-SPDiagnosticConfig -LogMaxDiskSpaceUsageEnabled
Set-SPDiagnosticConfig -LogDiskSpaceUsageGB <UsageInGB>


3. Do not Use the Verbose - Or use it only when required, then revert it back. Why? because SharePoint will log every action and consume  lot of disk space. so setting SharePoint diagnostic logging level to verbose will fill the disk space so quick!
Set-SPLogLevel -TraceSeverity Verbose . You can revert it to default: Clear-SPLogLevel

4. Take backups and delete them. Restrict the Logs by setting either size or Number of days. 
I would go for restrict the log space. If you specify the number of days for which logs are to be maintained by SharePoint, oldest files are deleted by SharePoint to maintain those many days log files. By default, diagnostic logging will keep on growing on the disk. So ideally you should restrict the disk space to be used for logging. 

5. Event log flooding protection? Yes, Of course! This will avoid repeating events in the Windows Event log.
Set-SPDiagnosticConfig -EventLogFloodProtectionEnabled

All of the above PowerShell cmdlets can be combined into one as:
Set-SPDiagnosticConfig -EventLogFloodProtectionEnabled -DaysToKeepLogs 5 -LogLocation "E:\Logs\SharePointULS\" -LogMaxDiskSpaceUsageEnabled -LogDiskSpaceUsageGB 1 

Frequently Asked Questions on SharePoint 2010 Diagnostic Logging  

Event Throttling
SharePoint diagnostic logging event throttling controls the types of event logs, based on the level of severity.

SharePoint diagnostic logging default
The default settings for all categories are as follows:
  •     Event Log: Information
  •     Trace Log: Medium Level
You can select the category and choose "Reset" to reset diagnostic logging.
Technet Reference: http://technet.microsoft.com/en-us/library/ee748619.aspx 

Correlation Id
When SharePoint encounters with an error, Correlation Id {GUID} is presented to the end user! ULS Viewer tools will parse the ULS logs for you, and allow the viewing of live ULS logs too! http://archive.msdn.microsoft.com/ULSViewer

SharePoint Logging Database (Named WSS_Logging - By Default)
Starting from SharePoint 2010, SharePoint Logging database is introduced to keep all logging information for all servers in the farm. By default this feature is disabled! Once these jobs are enabled, SharePoint will insert diagnostic logging data into a new SQL Server database. Follow these steps to get ULS tracelogs to WSS_Logging Database.
  1. Open the SharePoint Central Administration
  2. Navigate to the Monitoring section
  3. Select Review Job Definitions
  4. Click on the job Diagnostic Data Provider: Trace Log
  5. Click on the Enable button to enable it
  6. Click on Run Now, to start it immediately
So you can write queries like:
SELECT * FROM [ULSTraceLog] WHERE
       [CorrelationId] ='8C6031F8-A04F-4ADD-A1A7-1317AC5FD073'

Tools to analyze ULS Logs:
  1. You can use your favorite Notepad tool to open trace files for analysis (which would be painful!) or use the tool ULS Viewer Tools to analyze Diagnostic Logging ULS Logs
  2. SharePoint Diagnostic Studio 2010 (Part of SharePoint Administration Toolkit version 2.0) provides SharePoint administrators with a unified interface that can be used to gather relevant information from a farm
  3. To analyze ULS Log you can use ULS log viewer tool from codeplex: http://ulsviewer.codeplex.com/
SharePoint 2010 diagnostic logging category
You can write custom messages for diagnostic logging using the SPDiagnosticsService class. You can even control the diagnostic logging behavior programmatically using this class. (Not available in Sandboxed solutions)

SharePoint Diagnostic logging not working?
SharePoint logging features depending on the windows Service 'SharePoint 2010 Tracing'.  If diagnostic logging SharePoint not working, check this service status. Also Make sure your AppPool account is in the group performance log users.

Disable/Turn-off diagnostic logging SharePoint 2010
Select All category and set them to "None"!
sharepoint 2010 diagnostic logging categories


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Create - Delete - Get Managed Paths in SharePoint Programmatically

SharePoint Managed Paths can be manipulated programmatically with SharePoint object model (.Net / PowerShell.) or with STSADM command line tool.

Using STSADM Tool to Add/Remove Managed Path:

These two stsadm command line tool switches available to Add/Remove Managed paths in SharePoint.
  • Stsadm -o AddPath
  • Stsadm -o DeletePath
Syntax: 
AddPath:
stsadm -o addpath -url <managed path URL followed by web app URL> -type <explicitinclusion or wildcardinclusion>
E.g.:
stsadm -o addpath -url http://sharepoint.company.com/teams/ -type wildcardinclusion
Create/Delete/Get Managed Paths in SharePoint Programmatically

DeletePath:
Syntax:
stsadm -o deletepath -url <Managed Path URL with Web App>
E.g.
stsadm -o deletepath -url http://sharepoint.company.com/teams/

Technet Reference:http://technet.microsoft.com/en-us/library/cc263161%28v=office.12%29.aspx


Create/Delete/Get Managed Paths with PowerShell:

Create a New Managed Path
Use New-SPManagedPath cmdlet to create a new managed path in a web application on the SharePoint farm.

New-SPManagedPath –WebApplication "http://sharepoint.company.com" –RelativeURL "teams" 

By default, the managed path is created as a wildcard inclusion type. You can include the
Explicit switch to create a managed path of explicit inclusion type.

New-SPManagedPath –WebApplication "http://sharepoint.company.com" –RelativeURL
"/departments/" -Explicit

Remove a Managed Path
If you need to delete a managed path from a specific web application: use Remove-SPManagedPath cmdlet.
Remove-SPManagedPath -Identity "Teams" –WebApplication "http://sharepoint.company.com"

Reference: http://technet.microsoft.com/en-us/library/cc261845%28v=office.14%29.aspx

Check whether a Particular Managed Path Exists:
PowerShell offers one more cmdlet: Get-SPManagedPath to check the existence of a managed path. Say, for e.g. you may want to check whether a particular managed path exists or not before creating managed path. 

Get Managed Paths
Get-SPManagedPath -WebApplication "http://sharepoint.company.com" - Get-SPManagedPath displays all managed paths for the given web application.

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

 write-host "Enter the Web Application URL:"
 $WebAppURL=read-host
 write-host "Enter the Managed Path:" 
 $ManagedPath =read-host

 #Check whether the particular managed path exist already
 $ManagedPathExists = Get-SPManagedPath -WebApplication $WebAppURL -Identity $ManagedPath -ErrorAction SilentlyContinue

 if ($ManagedPathExists -eq $null)
 {
    #Go ahead and create the managed path
    New-SPManagedPath –RelativeURL $ManagedPath -WebApplication $WebAppURL
 }
 else
 {
    Write-Host "Managed path $ManagedPath already exists!"
 }

You can Create Managed Paths in C# Object Model as:

string webAppURL = "http://sharepoint.company.com";
string RequiredManagedPath ="teams";

//Get the web app
SPWebApplication WebApp = SPWebApplication.Lookup(new Uri(webAppURL));

//Get the Managed Paths of the web app
SPPrefixCollection Prefixes = WebApp.Prefixes;

   //Check If it doesn't exists!
   if (Prefixes.Contains(RequiredManagedPath) == false)
        {
           //Create the managed Path  
    SPPrefix prefix = WebApp.Prefixes.Add(RequiredManagedPath, SPPrefixType.ExplicitInclusion);
 }

Tail: What if I delete the Managed path in use?
Answer: Your SharePoint Sites under the specific managed path will result: HTTP 404 Page Not Found! Refer my post: SharePoint Managed Paths - FAQs - If you have any questions on SharePoint Managed paths!


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Sunday, December 2, 2012

Check Lock Status for All Site Collections in SharePoint

End user came with a compliant: "I'm receiving 'HTTP 403: The Website declined to Show this webpage' in some sites", in an intranet collaboration environment. Ah! This is because: site is locked with "No Access".
403 The Website declined to Show this webpage - SharePoint Site Locks
How to Check Site Lock Status?
  1. You can Navigate to: Central Administration > Application Management > Configure Quotas and Locks to get lock status.
  2. Get Lock status with STSADM
    stsadm -o getsitelock -URL http://sharepoint.crescent.com
  3. Retrieve Site lock status with PowerShell:
    Get-SPSite "http://sharepoint.crescent.com" | Select ReadOnly,Readlocked,WriteLocked

But for this case, End-user doesn't remember the URL. There are 5000+ site collections. How do I find which site collection has been locked with "No Access"? We have to retrieve lock status for all site collections. PowerShell comes to rescue again:

PowerShell Script to Get Lock status for all Site collections:
Add-pssnapin Microsoft.SharePoint.Powershell -ErrorAction silentlycontinue

#Get All Site Collections of a web app
$Sites = Get-SPWebApplication "http://sharepoint.crescent.com" | Get-SPSite -limit all | foreach {

#Check Lock Status

#No Locks Applied?
if ($_.ReadOnly -eq $false -and $_.ReadLocked -eq $false -and $_.WriteLocked -eq $false) 
{
$Result ="Unlocked"
}
#Read-only Lock?
elseif ($_.ReadOnly -eq $true -and $_.ReadLocked -eq $false -and $_.WriteLocked -eq $true) 
{
$Result = "Read-Only"
}
#Adding Content Prevented?
elseif ($_.WriteLocked -eq $true -and $_.ReadLocked -eq $false -and $_.ReadOnly -eq $false) 
{
$Result = "Adding Content Prevented"
}
#No Access?
elseif ($_.ReadOnly -eq $null -and $_.ReadLocked -eq $null -and $_.WriteLocked -eq $null) 
{
$Result="No Access"
}

#Write the Result to CSV file separeted with Tab character
$_.RootWeb.Title +"`t" + $_.URL + "`t" + $Result | Out-File LockStatus.txt -Append

}

To unlock a site collection use:
Set-SPSite -Identity http://sharepoint-sitecollection-url -LockState Unlock 
Fore more information on SharePoint site locks refer my post: Site Collection Locks in SharePoint

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Monday, November 26, 2012

SharePoint Managed Paths Explained

Let me document the Frequently Asked Questions on SharePoint Managed Paths during my training sessions:

What is Managed Path in SharePoint?

A managed path is a location within a web application in which you can have site collections. When you create a web application, there are two managed paths created with it. The first managed path is called the Root "/" path of explicit inclusion type. The second is called "sites" with wildcard inclusion path. SharePoint 2010 My Site host comes with "Personal" Wildcard managed path.

Why We need Managed Paths in SharePoint?
Managed Paths in SharePoint used to group multiple sites based on some criteria. Also helps to maintain a logical structure in SharePoint. Say, You want to group all Sales department sites, then you can have: http://company/sales/Site1/ , http://company/sales/Site2/, etc.


SharePoint managed path examples:
Lets take an example. A typical SharePoint URL could be: "http://company.com/sites/Sales/apac/"
Where
  • http://company.com - Web Application
  • Sites-  Managed path
  • Sales - Site collection
  • apac - Sub-site

Explicit vs Wildcard
There are two Types of Managed Paths we can create:
  1. Explicit inclusion : Path can be explicitly used for only one site collection. (E.g. http://company/sites/hr) and no site collections can be created underneath the path. (But sub-sites can be created under site collection)
  2. Wildcard inclusion: If you want to create site collections underneath a specific path, choose "Wildcard" (for example, "Sites" in http://server/sites/). Unlimited site collections can be created under the given path.
sharepoint 2010 define managed path

How to Configure Managed Paths for SharePoint 2010 Web Applications?
Managed Paths are defined at web application level. You can have different paths for different web applications. They cannot be defined for host header site collections. To define managed path in SharePoint 2010, Go to:
  1. Central Administration >> Application Management.
  2. In Application Management page, click on Manage Web Applications
  3. Click the Web application for which you want to configure Manage Paths 
  4. Now from the ribbon, click Managed Paths.
  5. From here you can configure Managed Paths for a particular web application.
  6. Once you are done with managed paths, click OK.

sharepoint web application managed path

Nested Managed paths
is it possible to nest a managed path under another managed path? Yes! You can create nested managed paths! Say for E.g. You create a Managed Path "/sites/" , then You create managed path as "/sites/sales". Now you can create site collections under each of these paths.

But you cannot create a site collection under /sites/  as "Sales", because once you create the managed path "Sales" under "Sites" it is marked as reserved!

SharePoint Managed Path Limits
Its a best practice to have SharePoint managed paths < 20. As per SharePoint 2010 Software boundaries and limits  20 Managed Paths can be created per Web application.You can expect performance issues if you exceed this limit!

Can I Create Site collections Under Root?
By default, Root Managed Path (/) is created as Explicit inclusion, which means you can create only one site collection at the root of the web application. However you can delete and Re-create it with Wildcard inclusion to enable site collections under Root.

How to Change site collection managed path
If you want to change the managed path of your site collection, You have to:
  • Backup your site collection
  • Delete your site collection
  • Restore your site collection with new managed path
Refer my post: How to Change Site Collection URL for step by step instructions.

What if I delete the Managed path in use?
Answer: Your SharePoint Sites under the specific managed path will result: HTTP 404 Page Not Found!

SharePoint Managed path not in list?
Managed Path Not available in Create Site Collection Page, After deleting the site collection which was occupying the specified managed path already ? Refer my article for the solution: Managed Path Not available

How to Create/Delete SharePoint Managed path Programmatically with C# object model or Powershell? 
To Manage SharePoint managed paths in C# object model and in PowerShell, Refer my article: Programmatically Get/Create/Delete Managed Paths in SharePoint


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


You might also like:

Related Posts Plugin for WordPress, Blogger...