Sunday, March 27, 2016

How to Activate Publishing Feature using PowerShell in SharePoint

Task: SharePoint Publishing sites used to create Public web sites, intranet portals, etc. We had to activate Publishing feature in SharePoint using PowerShell in scenarios, such as:
  • Activating Publishing feature through web user interface resulted in error!
  • Bulk activating publishing feature for all site collections and sites in a web application.
PowerShell to Activate Publishing Feature in SharePoint:
Publishing sites rely on "SharePoint Server Publishing Infrastructure" feature, which needs to be activated both at site collection and site level. To activate publishing
  • Navigate to Site Settings >> Click on "Site collection features" link under "Site collection administration
  • Click on "Activate" button next to "SharePoint Server Publishing Infrastructure"
    sharepoint 2013 enable publishing infrastructure powershell
SharePoint PowerShell to activate publishing feature at site collection:
Here is the PowerShell to activate publishing feature at site collection.
Enable-SPFeature -Identity "PublishingSite" -url "http://intranet.crescent.com"

Lets add some error handling & variables to it:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Variables
$SiteURL="http://intranet.crescent.com"
$FeatureName = "PublishingSite"

#Check if publishing feature is already activated in the site collection
$Feature = Get-SPFeature -site $siteURL | Where-object {$_.DisplayName -eq $FeatureName}
if($Feature -eq $null)
{    
    #Enable the Publishing feature 
    Enable-SPFeature -Identity $FeatureName -url $SiteURL -Confirm:$False
   
    Write-host "Publishing Feature Activated on $($SiteURL)" -ForegroundColor Green    
}
else
{
    Write-host "Publishing Feature is already Active on $($SiteURL)" -ForegroundColor Red
}

Enable SharePoint server publishing at site level:
We have to activate the Publishing feature at site level also.
  • Go back to Site Settings page >> Click on "Manage Site Features" link under "Site Actions" group
  • Click on Activate button next to "SharePoint Server Publishing"
This enables publishing feature at web level. To activate SharePoint server publishing using PowerShell, use this script:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Variables
$WebURL="http://intranet.crescent.com/Sales/"
$FeatureName = "PublishingWeb"

#Check if publishing feature is already activated in the site 
$Feature = Get-SPFeature -Web $WebURL | Where-object {$_.DisplayName -eq $FeatureName}
if($Feature -eq $null)
{    
    #Enable the Publishing feature 
    Enable-SPFeature -Identity $FeatureName -url $WebURL -Confirm:$False
   
    Write-host "Publishing Feature Activated on $($WebURL)" -ForegroundColor Green    
}
else
{
    Write-host "Publishing Feature is already Active on $($WebURL)" -ForegroundColor Red
}

Publishing feature must be enabled at site collection before enabling it to sub-sites!

Activate SharePoint server publishing infrastructure for with PowerShell for all site collections & sites in a web application:
At times, You may have to activate or deactivate SharePoint server publishing infrastructure using PowerShell for all webs in entire site collection or even all site collections in the entire web application. Here is the script:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Variables
$WebAppURL="http://intranet.crescent.com/"
$SiteFeatureName = "PublishingSite"
$WebFeatureName = "PublishingWeb"

#Get all site collections of the web app and iterate through
$SiteColl= Get-SPSite -WebApplication $WebAppURL -Limit ALL
Foreach($Site in $SiteColl)
{ 
    write-host "Processing site collection:"$Site.URL -ForegroundColor Yellow 
    #Check if publishing feature is already activated in the site 
    $Feature = Get-SPFeature -Site $Site.URL | Where-object {$_.DisplayName -eq $SiteFeatureName}

    if($Feature -eq $null)
    {    
        #Enable the Publishing feature 
        Enable-SPFeature -Identity $SiteFeatureName -url $Site.URL -Confirm:$False
   
        Write-host "Publishing Feature Activated on $($Site.URL)" -ForegroundColor Green    
    }
    else
    {
        Write-host "Publishing Feature is already Active on $($Site.URL)" -ForegroundColor Red
    }

    #Loop through each web in the site collection
    Foreach($Web in $Site.AllWebs)
    {
        write-host "Processing Web"$Web.URL -ForegroundColor Yellow
        #Check if publishing feature is already activated in the web 
        $Feature = Get-SPFeature -Web $Web.URL | Where-object {$_.DisplayName -eq $WebFeatureName}
        if($Feature -eq $null)
        {    
            #Enable the Publishing feature 
            Enable-SPFeature -Identity $WebFeatureName -url $Web.URL -Confirm:$False
   
            Write-host "Publishing Feature Activated on $($Web.URL)" -ForegroundColor Green    
        }
        else
        {
            Write-host "Publishing Feature is already Active on $($Web.URL)" -ForegroundColor Red
        }
    }
}


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


Create Task List in SharePoint using PowerShell

Requirement:  In SharePoint, create task list using PowerShell!

PowerShell to create task list in SharePoint:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Variables
$WebURL="http://intranet.crescent.com"
$ListName="Project Tasks"
$ListDescription ="Task list to manage project tasks"

#Task list template
$ListTemplate = [Microsoft.SharePoint.SPListTemplateType]::Tasks

#Get the Web
$Web = Get-SPWeb $WebURL

#Check if the task list exists already
$TaskList = $Web.Lists.TryGetList($ListName)
if($TaskList -ne $null)
{
    Write-host "Task list '$($ListName)' exists already!" -ForegroundColor Red
}
else
{
    #Create the task list
    $Web.Lists.Add($ListName,$ListDescription,$ListTemplate) | Out-Null

    #Set "Show in Quick Launch" property for the list
    $TaskList = $Web.Lists[$ListName]
    $TaskList.OnQuickLaunch = $True
    $TaskList.Update()

    Write-host "Task list '$($ListName)' Created successfuly!" -ForegroundColor Green
}
This PowerShell script creates SharePoint task list.
sharepoint 2013 powershell create task list

To Add a task in Task list using PowerShell, use: Create a Task in SharePoint Task List using Powershell

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


Saturday, March 26, 2016

Fix "Drives are running out of free space" Error in SharePoint Health Analyzer

Problem: 
SharePoint Health Analyzer in Central Admin site gave the alert banner "The SharePoint Health Analyzer has detected some critical issues that require your attention. View these issues". On checking, found "Drives are running out of free space" and "Drivers are at risk of running out of disk space" errors logged!
SharePoint Health Analyzer detected an error - Drives are running out of free space
Also, this found an error message in Windows event log with an Event ID: 2138
The SharePoint Health Analyzer detected a condition requiring your attention.  Drives are at risk of running out of free space.
Available drive space is less than five times the value of physical memory. This is dangerous because it does not provide enough room for a full memory dump with continued operation. It also could cause problems with the Virtual Memory swap file: New Volume (SharePoint-Server- C:\).
Examine the failing servers and delete old logs or free space on the drives. For more information about this rule, see "http://go.microsoft.com/fwlink/?LinkID=142688".


Root cause: By default, SharePoint needs at least 2 * RAM size of free disk space on C:\ of your SharePoint servers. E.g If you have 16 GB of RAM in your server, then SharePoint checks if you have 80GB of free space in your system drive. If you don't then SharePoint logs an Error in health analyzer. If you don't have 5xRAM Size, then SharePoint logs an Warning.

Solution:
How do I fix this issue? Well, you have to increase the disk space on your C:\ to 5 x RAM Size (or remove old files, cleanup Logs, etc). In General, If you have enough free space, This alert can be ignored.

You can also disable this rule in Health analyzer to get rid of the alert. To disable this rule, follow below steps:
  1. Go to SharePoint 2013 Central admin site
  2. Click on Monitoring from the left navigation
  3. Under "Health Analyzer", click on "Review rule definitions"
  4. Under Availability category, click on the "Drives are running out of free space" rule.
  5. In the view page, Click on "Edit Item" and then uncheck the "Enabled" checkbox.
  6. Hit "Save" button to commit your changes.
    sharepoint Drives are running out of free space


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


Monitor SharePoint Web Sites Availability and Send Alert Email using PowerShell

Requirement: Script to monitor SharePoint web sites and Trigger an Alert Email when something goes wrong!

PowerShell script to Monitor SharePoint Sites:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Configuration Parameters
$EmailFrom = "SharePointMonitor@crescent.com"
$EmailTo = @("salaudeen.rajack@crescent.com")
$EmailSubject = "Alert: SharePoint site is Down!"
 
#Get Outgoing Email Server of the SharePoint Farm
$SMTPServer= (Get-SPWebApplication -IncludeCentralAdministration | Where { $_.IsAdministrationWebApplication } ) | % {$_.outboundmailserviceinstance.server.address}

#Make a web request to check site status
$WebClient = New-Object System.Net.WebClient
$WebClient.UseDefaultCredentials = $true

#Iterate through each web application
Foreach($WebApp in (Get-SPWebApplication))
{
    $EmailBody=""
    #Get the timestamp
    $TimeStamp = Get-Date –f "yyyy-MM-dd HH:mm:ss"

    try
    {
        $Page = $WebClient.DownloadString($WebApp.Url)
    }
    catch [Exception]
    {
        $EmailBody += "The SharePoint site: $($WebApp.Url) is unavailable. Please take necessary action!<br><br>"
        $EmailBody += "<b>URL:</b> " + $WebApp.Url + "<br><br>"
        $EmailBody += "<b>Exception:</b> " + $_.Exception.message + "<br><br>"
        $EmailBody += "<b>Timestamp:</b> " + $TimeStamp

        #Send an Alert Email message
        Send-MailMessage -To $EmailTo -Subject $EmailSubject -Body $EmailBody -SmtpServer $SMTPServer -From $EmailFrom -BodyAsHtml -usessl
    }
} 

Here is the alert Email in action:
Monitor SharePoint Sites availability and Sent Alert Email when things go wrong using PowerShell

Schedule this script in Windows task scheduler to run for every 10 minutes.

Update: What if the site loaded with an error? E.g. "Sorry, something went wrong" error message.

Here is the updated script to check if the site loaded with error message:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Configuration Parameters
$EmailFrom = "SharePointMonitor@crescent.com"
$EmailTo = @("salaudeen.rajack@crescent.com")
$EmailSubject = "Alert: SharePoint site is Down!"
 
#Get Outgoing Email Server of the SharePoint Farm
$SMTPServer= (Get-SPWebApplication -IncludeCentralAdministration | Where { $_.IsAdministrationWebApplication } ) | % {$_.outboundmailserviceinstance.server.address}

#Make a web request to check site status
$WebClient = New-Object System.Net.WebClient
$WebClient.UseDefaultCredentials = $true

#Iterate through each web application
Foreach($WebApp in (Get-SPWebApplication))
{
    $EmailBody=""
    #Get the timestamp
    $TimeStamp = Get-Date –f "yyyy-MM-dd HH:mm:ss"

    try
    {
        $Page = $WebClient.DownloadString($WebApp.Url)

        if($Page.Contains("Sorry, something went wrong"))
        {            
            $EmailBody += "The SharePoint site: $($WebApp.Url) encountered with an unexpected error. Please take necessary action!<br><br>"
            $EmailBody += "<b>URL:</b> " + $WebApp.Url + "<br><br>"
            $EmailBody += "<b>Timestamp:</b> " + $TimeStamp

            #Send an Alert Email message
            Send-MailMessage -To $EmailTo -Subject $EmailSubject -Body $EmailBody -SmtpServer $SMTPServer -From $EmailFrom -BodyAsHtml -usessl    
        }
    }
    catch [Exception]
    {
        $EmailBody += "The SharePoint site: $($WebApp.Url) is unavailable. Please take necessary action!<br><br>"
        $EmailBody += "<b>URL:</b> " + $WebApp.Url + "<br><br>"
        $EmailBody += "<b>Exception:</b> " + $_.Exception.message + "<br><br>"
        $EmailBody += "<b>Timestamp:</b> " + $TimeStamp

        #Send an Alert Email message
        Send-MailMessage -To $EmailTo -Subject $EmailSubject -Body $EmailBody -SmtpServer $SMTPServer -From $EmailFrom -BodyAsHtml -usessl
    }
}


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


Monday, March 21, 2016

Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)) on Get-SPWeb, New-SPUser, Get-SPUser, Set-SPUser, etc.

Problem: Getting "Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))" on running PowerShell cmdlets, such as: Get-SPWeb, New-SPUser, Get-SPUser, Set-SPUser, etc.
Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)) on Get-SPWeb, New-SPUser, Get-SPUser, Set-SPUser

Solution: 
Add a web application user policy with Full control for the Farm Administrator who runs the Script!
  • Open SharePoint 2016/2013/2010 Central Administration site as a Farm Administrator
  • Click Application Management >> Select Manage Web Applications.
  • Select your target web application >> Click the User Policy button from the ribbon.
  • From the Policy for Web Application dialog box, click on "Add Users" link.
  • Select All Zones for the web application and click on Next
  • Enter the user account and Select the permission policy level as "Full Control"
  • Click Finish to save your changes. 


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


Tuesday, March 15, 2016

Remove Checkbox from SharePoint Listview Web Part

Requirement:
Remove checkbox from SharePoint 2016 listview header! For a SharePoint links list, we had to remove checkbox from listview.

Solution: 
To remove checkbox in SharePoint list header, follow these steps:
  • Click on "Modify View" button from the List Tab of the ribbon menu.
  • Scroll down and uncheck "Allow individual item checkboxes" tick mark under Tabular View!
     sharepoint 2013 remove checkbox from listview
  • Click on "OK" button to save your changes. This removes the checkbox in list view.
Remove checkbox in SharePoint xsltlistviewwebpart:
For Dataview/XSLTListViewwebpart, Open the view page in SharePoint Designer, Edit the list view page, Set TabularView="False" under "View" tag to remove checkbox!
 
Remove checkbox from SharePoint list using PowerShell:
Use this PowerShell script to remove checkbox from listview web part.
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Configuration Parameters
$WebURL="http://intranet.crescent.com/"
$ListName="Quick Links"
$ViewName="All Links"

#Get web, List and View objects
$Web = Get-SPWeb $WebURL
$List = $Web.Lists[$ListName]
$View = $List.Views[$ViewName]

#sharepoint view remove checkbox
$View.TabularView = $False
$View.Update()
Write-host "Checkboxes Removed from SharePoint View!"
and here is the result:
sharepoint 2013 remove checkbox listview


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


How to Enable Client Integration in SharePoint 2013

Client integration setting in SharePoint enables or disables SharePoint-Client applications integration, such as starting client application based on the document types. It also provides features such as Open in Explorer view, Upload multiple documents, Edit in datasheet, etc.

Enable client integration in SharePoint 2013 central administration
SharePoint client integration is not enabled in forms authentication, by default. To activate client integration in SharePoint, follow these steps:
  • Go to SharePoint 2013 Central Administration >> Application Management >> Click on "Manage Web Applications" under Web Applications.
  • Select your target web application for which you would like to enable or disable client integration.
  • Click on "Authentication Providers" button from the ribbon.
    sharepoint 2013 client integration setting
  • Click on the Zone name - Default in the "Authentication Providers" popup.
    sharepoint 2013 enable client integration
  • In the edit authentication providers page, under "Client Integration" section, Set "Enable Client Integration?" setting to "Yes".
    sharepoint client integration disable
  • Click Save to commit your changes.

SharePoint permission to use client integration features:
Although the client integration is enabled or disabled at web application level, in order to utilize client integration features, user must be granted with "Use Client Integration Features" permission from his/her permission level.
  • From site settings >> Click on Site Permissions >>Click on Permission Levels button from the ribbon
  • Pick the permission level granted to the user, such as "Edit" or some other custom permission level
  • You'll see list of base permissions associated with the particular permission level. Under Site Permissions, make sure "Use Client Integration Features" is selected.
    sharepoint permission use client integration features
SharePoint 2013 enable-disable client integration using PowerShell:
In some cases, you may have to disable client integration feature in SharePoint.
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Configuration parameters
$WebAppURL="http://intranet.crescent.com/"
$Zone="Default"
$ClientIntegrationOption=$False

#Get the web application and current setting
$WebApp = Get-SPWebApplication $WebAppURL
$webApp.IisSettings[$Zone].EnableClientIntegration

#enable or disable client integration
$webApp.IisSettings[$Zone].EnableClientIntegration = $ClientIntegrationOption
$WebApp.Update()
Based on the option you specified in the $ClientIngrationOption flag, it either enables or disables client integration feature.

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


SharePoint 2016 RTM is Released!

So the waiting period is over! SharePoint 2016 is in its RTM now!
sharepoint 2016 RTM download

Download SharePoint 2016 RTM Trial from here: https://www.microsoft.com/en-us/download/details.aspx?id=51493

180 day Trial key: NQGJR-63HC8-XCRQH-MYVCH-3J3QR

What's New: Fast Site Collection Creation, Durable Links, Hybrid Features, MinRoles, Large File support, etc.

What's Lost: No more SharePoint Foundation, No Stand-alone Install Mode (with SQL Express), No FIM, etc.

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


Sunday, March 13, 2016

Disable Continuous Crawl in SharePoint 2013 using PowerShell

Continuous Crawl in SharePoint 2013 helps to keep the search results upto date. In some situations like maintenance, Index reset, etc you may have to turn-off continuous crawl in SharePoint. To disable continuous crawl on a specific SharePoint content source, Follow these steps:
  • Login to SharePoint 2013 Central Administration as a Farm administrator. In Central Administration, Under Application Management, click on Manage service applications,
  • and Pick your Search service application
  • In Search Service Administration page, click on Content Sources link under Crawling section of the left navigation menu.
  • In the Manage Content Sources page, click on the drop down arrow from the SharePoint content source to which you want to disable continuous crawl.
  • Select Disable Continuous crawl and Confirm that you want to disable continuous crawl by clicking OK. You can also disable continuous crawl by selecting Incremental Crawls option from the edit content sources page, which disables continuous crawl. 
    sharepoint 2013 disable continuous crawl powershell
SharePoint 2013 disable continuous crawl using PowerShell:
Use this PowerShell script to disable continuous crawl for a specific content source in SharePoint 2013 or SharePoint 2016.
#Get Search service application
$SSA =  Get-SPEnterpriseSearchServiceApplication
 
#Get the content source by name
$ContentSource = Get-SPEnterpriseSearchCrawlContentSource -SearchApplication $SSA -Identity "Local SharePoint sites"
 
#Check if Continuous Crawls is already disabled
if($ContentSource.EnableContinuousCrawls -eq $False)
{
    Write-host "Continuous Crawl is already Disabled on this content source!" -ForegroundColor Red
}
else
{
    #Disable continuous crawl sharepoint 2013
    Set-SPEnterpriseSearchCrawlContentSource -Identity $ContentSource -EnableContinuousCrawls $False
    Write-host "Disabled Continuous Crawl Successfully!" -ForegroundColor Green
}

Disable continuous crawl SharePoint 2016 with PowerShell
Lets disable continuous crawl for all SharePoint content sources.
#Get Search service application
$SSA =  Get-SPEnterpriseSearchServiceApplication

#Get all SharePoint content sources
$SPContentSources = Get-SPEnterpriseSearchCrawlContentSource -SearchApplication $SSA | Where-object {$_.Type -eq "SharePoint"} 

foreach ($ContentSource in $SPContentSources) 
{ 
    #Check if Continuous Crawls is disabled already
    if($ContentSource.EnableContinuousCrawls -eq $false)
    {
     Write-host "Continuous Crawl is already Disabled for $($ContentSource.Name)!" -ForegroundColor Yellow
    }
    else
    {
        #enable continuous crawl sharepoint 2013
        Set-SPEnterpriseSearchCrawlContentSource -Identity $ContentSource -EnableContinuousCrawls $False
     Write-host "Disabled Continuous Crawl Successfully for $($ContentSource.Name)" -ForegroundColor Green
    }
}


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


Enable Continuous Crawl in SharePoint 2013 using PowerShell

Continuous Crawl was introduced in SharePoint 2013 to keep the search results as fresh as possible.
To enable Continuous crawl in SharePoint 2013, follow these steps:
  • Login to SharePoint 2013 Central Administration as a Farm Administrator. In Central Administration, Click on Manage service applications under the Application Management tab
  • Click on your Search service application.
  • In the Search Service Administration page, click on Content Sources link from the left navigation.
  • On the Manage Content Sources page, click the SharePoint content source to which you want to enable continuous crawl.
  • Scroll down and select "Enable Continuous Crawls" option under the Crawl Schedules section.
    sharepoint 2013 enable continuous crawl powershell
  • Click OK to save your changes.
SharePoint 2016: Enable continuous crawl with PowerShell
Here is the PowerShell script to enable continuous crawl in SharePoint 2013 or SharePoint 2016.
#Get Search service application
$SSA =  Get-SPEnterpriseSearchServiceApplication

#Get the content source by name
$ContentSource = Get-SPEnterpriseSearchCrawlContentSource -SearchApplication $SSA -Identity "Local SharePoint sites"

#Check if Continuous Crawls is already enabled
if($ContentSource.EnableContinuousCrawls -eq $true)
{
 Write-host "Continuous Crawl is already Enabled for this content source!" -ForegroundColor Red
}
else
{
        #enable continuous crawl sharepoint 2013
        Set-SPEnterpriseSearchCrawlContentSource -Identity $ContentSource -EnableContinuousCrawls $True
        Write-host "Enabled Continuous Crawl Successfully!" -ForegroundColor Green
}

Enable continuous crawl for all SharePoint 2013 content sources using PowerShell
While the above script enables Continuous crawl for given content source name, Lets enable continuous crawl for all SharePoint content source in SharePoint 2016:
#Get Search service application
$SSA =  Get-SPEnterpriseSearchServiceApplication

#Get all SharePoint content sources
$SPContentSources = Get-SPEnterpriseSearchCrawlContentSource -SearchApplication $SSA | Where-object {$_.Type -eq "SharePoint"} 

foreach ($ContentSource in $SPContentSources) 
{ 
    #Check if Continuous Crawls is already enabled
    if($ContentSource.EnableContinuousCrawls -eq $true)
    {
 Write-host "Continuous Crawl is already Enabled for $($ContentSource.Name)!" -ForegroundColor Yellow
    }
    else
    {
        #enable continuous crawl sharepoint 2013
        Set-SPEnterpriseSearchCrawlContentSource -Identity $ContentSource -EnableContinuousCrawls $True
        Write-host "Enabled Continuous Crawl Successfully for $($ContentSource.Name)" -ForegroundColor Green
    }
}


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


Set SharePoint 2013 Continuous Crawl Interval using PowerShell

Continuous crawl helps to keep the search results as fresh as possible. By default, SharePoint 2013 continuous crawl frequency is set to 15 minutes. In some cases, you may have to adjust the schedule for continuous crawl frequency. This can be done only through PowerShell as there is no GUI to adjust continuous crawl schedule.

SharePoint 2013 continuous crawl interval using PowerShell
Use this PowerShell script to set continuous crawl frequency in SharePoint 2013 or SharePoint 2016.

Get the current crawl schedule
$SearchServiceApp = Get-SPEnterpriseSearchServiceApplication
$SearchServiceApp.GetProperty("ContinuousCrawlInterval")

SharePoint 2013 continuous crawl interval PowerShell:
#Set sharepoint continuous crawl interval
$SearchServiceApp = Get-SPEnterpriseSearchServiceApplication
$SearchServiceApp.SetProperty("ContinuousCrawlInterval",5)
This sets the continuous crawl frequency to 5 Minutes. Related Post: SharePoint 2013 continuous crawl explained

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


The Database name located at the specified database server contains user-defined data.- Error in SharePoint Products Configuration Wizard

Error:
SharePoint Products Configuration Wizard:  
The Database name located at the specified database server contains user-defined data. Databases must be empty before they can be used. Delete all of the tables, stored procedures, and other objects, or use a different database.
The Database name located at the specified database server contains user-defined data

Root cause:
This is due to the fact, previous installation failed in between and left the SharePoint_Config database in SQL Server!

Solution:
Delete the SharePoint_Config database created by the previous installation!


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


Saturday, March 12, 2016

Change Timer Job Schedule in SharePoint using PowerShell

Requirement:  Change timer job schedule in SharePoint for "User Profile Service Application - Activity Feed Job".

Solution: To Set SharePoint timer job schedule, follow these steps:
  • Go to the Central Administration >> Monitoring >> Timer Job >> Review job definitions
  • Find "User Profile Service Application - Activity Feed Job", 
  • In Edit Timer job page, set up the activity feed sync time according to your needs. By default, its set to run for every 10 Minutes.
    sharepoint timer job schedule powershell
SharePoint PowerShell to change timer job schedule
SharePoint 2013 timer job Schedules can be set through the Set-SPTimerJob cmdlet. Here is the PowerShell script to change timer job schedule.
#Timer job Display name 
$TimerJobName="User Profile Service Application - Activity Feed Job"

#Get the Timer job
$TimerJob = Get-SPTimerJob | Where-Object { $_.displayname -like $TimerJobName }

#Set sharepoint timer job schedule powershell
Get-SPTimerJob $TimerJob | Set-SPTimerJob -Schedule "Every 5 minutes between 0 and 59"

Write-host "Timer Job Schedule updated!" -ForegroundColor Green
This script sets the timer job schedule to 5 minutes!

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


Enable-Disable Timer Jobs using PowerShell in SharePoint

Timer jobs perform specific tasks in SharePoint through Windows Timer service, such as sending email alerts at a scheduled time. In SharePoint Central Administration site you can check the timer jobs, disable or enable specific timer jobs.

PowerShell Script to Check Timer Job Status:
#Function to Check Timer job status
Function Get-TimerJobStatus($TimerJobName)
{
    $TimerJob = Get-SPTimerJob | Where-Object { $_.displayname -like $TimerJobName } 
    if($TimerJob -eq $null)
    {
        Write-host "Timer job not found!" -ForegroundColor Red
        return
    }
    $TimerJobDisabled = $TimerJob | Select -ExpandProperty IsDisabled
    if($TimerJobDisabled)
    {
        Write-host "Timer Job is Disabled!"  -ForegroundColor Yellow
    }
    else
    {
        Write-host "Timer Job is Enabled!"  -ForegroundColor Green
    }
    
}

$TimerJobName="My Site Cleanup Job"
Get-TimerJobStatus $TimerJobName

How to Disable a Timer job in SharePoint?
To disable a timer job, Head on to Central Administration >> Monitoring >> Timer Jobs >> Review job definitions >> pick your target from the list of timer jobs in SharePoint 2013 >> Click on "Disable" button to disable a Timer job.
disable sharepoint timer job powershell

Disable SharePoint timer job using PowerShell
#Function to Disable a Timer job
Function Disable-TimerJob($TimerJobName)
{
    $TimerJob = Get-SPTimerJob | Where-Object { $_.displayname -like $TimerJobName } 
    if($TimerJob -eq $null)
    {
        Write-host "Timer job not found!" -ForegroundColor Red
        return
    }
    $TimerJobDisabled = $TimerJob | Select -ExpandProperty IsDisabled
    if($TimerJobDisabled)
    {
        Write-host "Timer Job is already Disabled!" -ForegroundColor Yellow
    }
    else
    {
        $TimerJob | Disable-SPTimerJob 
        Write-host "Timer Job Disabled!" -ForegroundColor Green
    }
    
}

#Timer job name to disable
$TimerJobName="My Site Cleanup Job"

#Call the function to Disable Timer job
Disable-TimerJob $TimerJobName

Activate timer job in SharePoint:
To activate a disabled timer job, Go to:
  • Central Administration >> Monitoring >> Timer Jobs 
  • Review job definitions >> pick your target from the list of timer jobs in SharePoint 2013 
  • Click on "Enable" button to activate the timer job.
enable timer job using powershell in sharepoint
This enables the disabled timer job in SharePoint 2013.

SharePoint enable timer job with PowerShell:
#Function to Enable a Timer job
Function Enable-TimerJob($TimerJobName)
{
    $TimerJob = Get-SPTimerJob | Where-Object { $_.displayname -like $TimerJobName } 
    if($TimerJob -eq $null)
    {
        Write-host "Timer job not found!" -ForegroundColor Red
        return
    }
    $TimerJobDisabled = $TimerJob | Select -ExpandProperty IsDisabled
    if($TimerJobDisabled)
    {
        $TimerJob | Enable-SPTimerJob 
        Write-host "Timer Job Enabled!" -ForegroundColor Green
    }
    else
    {
        Write-host "Timer Job is Already Enabled!" -ForegroundColor Yellow
    }    
}

#Timer job name to Enable
$TimerJobName="My Site Cleanup Job"

#Call the function to Enable Timer job
Enable-TimerJob $TimerJobName 
This activates timer job in SharePoint 2010 with PowerShell.

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


Wednesday, March 9, 2016

SharePoint Online: Export List Items to CSV using PowerShell

Requirement: 
Export SharePoint online list items to CSV file from client side.

PowerShell script to Export SharePoint List Items to CSV from Client Side (CSOM):
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
 
##Variables for Processing
$SiteUrl = "https://crescent.sharepoint.com/sites/poc/"
$ListName="Employee"
$ExportFile ="c:\Scripts\ListRpt.csv"
$UserName="Salaudeen@crescent.com"
$Password ="Password goes here"

#Setup Credentials to connect
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName,(ConvertTo-SecureString $Password -AsPlainText -Force))

#Set up the context
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl) 
$Context.Credentials = $credentials
 
#Get the List
$List = $Context.web.Lists.GetByTitle($ListName)

#Get All List Items
$Query = New-Object Microsoft.SharePoint.Client.CamlQuery
$ListItems = $List.GetItems($Query)
$context.Load($ListItems)
$context.ExecuteQuery()

#Array to Hold List Items 
$ListItemCollection = @() 

#Fetch each list item value to export to excel
 $ListItems |  foreach {
    $ExportItem = New-Object PSObject 
    $ExportItem | Add-Member -MemberType NoteProperty -name "Title" -value $_["Title"]
    $ExportItem | Add-Member -MemberType NoteProperty -Name "Department" -value $_["Department"]
  
    #Add the object with above properties to the Array
    $ListItemCollection += $ExportItem
 }
#Export the result Array to CSV file
$ListItemCollection | Export-CSV $ExportFile -NoTypeInformation 

Write-host "List data Exported to CSV file successfully!"

Related Posts:


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


Wednesday, March 2, 2016

Copy Files Between Document Libraries in SharePoint using PowerShell

Here is my PowerShell script to copy files between SharePoint document libraries:

PowerShell Script to Copy a File from One Library to Another:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Variables for Processing
$WebURL="https://portal.crescent.com/sites/Sales/"
$SourceFile="https://portal.crescent.com/sites/Sales/TeamDocs/InvoiceTemp.xlsx"
$TargetLibrary="Invoice Documents"

#Get Objects
$Web = Get-SPWeb $WebURL
$SourceFile = $Web.GetFile($SourceFile)
$TargetLibrary = $Web.GetFolder($TargetLibrary)

#Copy the file into the Target library
$File = $TargetLibrary.Files.Add($SourceFile.Name, $SourceFile.OpenBinary(), $true)

#Copy Meta-Data
$Item = $File.Item
$item["Created"] = $SourceFile.TimeCreated.ToLocalTime()
$item["Modified"] = $SourceFile.TimeLastModified.ToLocalTime()
$item["Author"] = $SourceFile.Author
$item["Editor"] = $SourceFile.ModifiedBy
#Update
$Item.UpdateOverwriteVersion()

PowerShell Script to Copy All Files Between Document Libraries:
Lets copy all files and folder from one library to another along with their meta-data (Excluding: the above!)
sAdd-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Custom Function to Copy Files from Source Folder to Target
Function Copy-Files($SourceFolder, $TargetFolder)
{
    write-host "Copying Files from:$($SourceFolder.URL) to $($TargetFolder.URL)"
    #Get Each File from the Source 
    $SourceFilesColl = $SourceFolder.Files

    #Iterate through each item from the source
    Foreach($SourceFile in $SourceFilesColl) 
    {
        #Copy File from the Source
        $NewFile = $TargetFolder.Files.Add($SourceFile.Name, $SourceFile.OpenBinary(),$True)
 
        #Copy Meta-Data from Source
        Foreach($Field in $SourceFile.Item.Fields)
        {
            If(!$Field.ReadOnlyField)
            {
                if($NewFile.Item.Fields.ContainsField($Field.InternalName))
                {
                    $NewFile.Item[$Field.InternalName] = $SourceFile.Item[$Field.InternalName]
                }
            }
        }
        #Update
        $NewFile.Item.UpdateOverwriteVersion()
    
        Write-host "Copied File:"$SourceFile.Name
    }
    
    #Process SubFolders
    Foreach($SubFolder in $SourceFolder.SubFolders)
    {
        if($SubFolder.Name -ne "Forms")
        {
            #Check if Sub-Folder exists in the Target Library!
            $NewTargetFolder = $TargetFolder.ParentWeb.GetFolder($SubFolder.Name)
 
            if ($NewTargetFolder.Exists -eq $false)
            {
                #Create a Folder
                $NewTargetFolder = $TargetFolder.SubFolders.Add($SubFolder.Name)
            }
            #Call the function recursively
            Copy-Files $SubFolder $NewTargetFolder
        }
    }
}

#Variables for Processing
$WebURL="http://portal.crescent.com/sites/sales/"
$SourceLibrary ="Team Docs"
$TargetLibrary = "Sales Documents"

#Get Objects
$Web = Get-SPWeb $WebURL
$SourceFolder = $Web.GetFolder($SourceLibrary)
$TargetFolder = $Web.GetFolder($TargetLibrary)

#Call the Function to Copy All Files
Copy-Files $SourceFolder $TargetFolder

Copy Documents between Sites, Site Collections, Web Applications:
How about copying between Sites? Well, just change the below lines in the script.
#Variables for Processing
$SourceWeb = "http://Your-Source-Web-URL"
$TargetWeb = "http://Your-Target-Web-URL"

$SourceLibrary ="Team Docs"
$TargetLibrary = "Shared Documents"

$SourceFolder = $Source.GetFolder($SourceLibrary)
$TargetFolder = $TargetWeb.GetFolder($TargetLibrary)

#Call the Function to Copy All Files
Copy-Files $SourceFolder $TargetFolder


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...