Tuesday, April 29, 2014

Sharepoint Logs not working with Error: Usage log retention limit reached.

Error:

Usage log retention limit reached.  Some old usage log files have been deleted


1. Open the command prompt and Navigate to the stsadm directory i.e. cd \Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\BIN
2. When in that directory simply type: “stsadm -o provisionservice -action start -servicetype spwebservice
3. Restart  IIS.

Wednesday, March 12, 2014

SharePoint Web Services Round Robin Service Load Balancer Event: EndpointFailure

Hello, 
today I want to tell you about some case I recently had with  SharePoint  Farm. Hope it can help you to resolve the issue faster then me. :)

Problem 

Event Log has the following critical error:

SharePoint Web Services Round Robin Service Load Balancer Event: EndpointFailure
Process Name: w3wp
Process ID: 5992
AppDomain Name: .......
AppDomain ID: 2
Service Application Uri: urn:schemas-microsoft-com:sharepoint:service:5433e283601b4d7e8e50ee71d6f16982#authority=urn:uuid:992f0d70913242d1a4930c0823df0e0b&authority=https://<server>:<port>/Topology/topology.svc
Active Endpoints: 1
Failed Endpoints:3


This message appeared in the Event Viewer every 10 minutes 3 times (for each server in the farm)

Description:

SharePoint Farm configuration has:
 One App server - 1
 Three Web Front End servers - 3
 One SQL server - 1

After spending a lot of time of investigation and reading about this issue in the Internet, I could not find any reasonable solution to resolve the issue.

One of the solution was to stop and start Managed Metadata service, but I decided not to do that. 

I  looked into the ULS log file of SharePoint and found an interesting message:

Error encountered in background cache check System.UnauthorizedAccessException: The current user has insufficient permissions to perform this operation.    
 at Microsoft.SharePoint.Taxonomy.MetadataWebServiceApplicationProxy.<>c__DisplayClass2c.<RunOnChannel>b__2b()    
 at Microsoft.Office.Server.Security.SecurityContext.RunAsProcess(CodeToRunElevated secureCode)    
 at Microsoft.SharePoint.Taxonomy.MetadataWebServiceApplicationProxy.<>c__DisplayClass2c.<RunOnChannel>b__2a()    
 at Microsoft.Office.Server.Utilities.MonitoredScopeWrapper.RunWithMonitoredScope(Action code)    
 at Microsoft.SharePoint.Taxonomy.MetadataWebServiceApplicationProxy.RunOnChannel(CodeToRun codeToRun, Double operationTimeoutFactor)    
 at Microsoft.SharePoint.Taxonomy.MetadataWebServiceApplicationProxy.ReadApplicationSettings(Guid rawPartitionId)    
 at Microsoft.SharePoint.Taxonomy.MetadataWebServiceApplicationProxy.ReadServiceApplicationSettings()    
 at Microsoft.SharePoint.Taxonomy.MetadataWebServiceApplicationProxy.get_ServiceApplicationSettings()    
 at Microsoft.SharePoint.Taxonomy.MetadataWebServiceApplicationProxy.TimeToCheckForUpdates()    
 at Microsoft.SharePoint.Taxonomy.Internal.TaxonomyCache.CheckForChanges(Boolean enforceUpdate)    
 at Microsoft.SharePoint.Taxonomy.Internal.TaxonomyCache.<LoopForChanges>b__0().


I knew that one my of my colleague recently worked on an other project and it was added as the separate web application on the same SharePoint Farm. Then I looked at the "user" field in the Event Viewer of the "SharePoint Web Services Round Robin Service Load Balancer Event: EndpointFailure", and the Application Pool user of the new web application was different from the main web application, as it should be (each web app has it on app pool).

So I went to the SharePoint Central Administration and did the following steps:

  1. Go to SharePoint Central Administration Site –> Application Management –> [Service Applications] –> Manage service applications
  2. Highlight the Managed Metadata Service that your web application is associated with. (Do not click on the link, just click somewhere else on that row to highlight it)
  3. Click on Permissions button in the ribbon area.
  4. Add the application pool account  (in my case it was user for new web application, that my colleague worked on )  used by web application and give it at least ‘Read Access to Term Store"
After monitoring a couple of days the message disappeared from the event viewer. Then I removed the user from the permissions and the message appeared again with 10 minutes time period.

It seems that the problem was resolved, but I decided to spent some more time and to understand why the application pool account was not added automatically to the permissions of the Manage service application and possible  find other solution to resolve the issue with "round robin" message. I had only an information that the new web application was added after the main web application.

So I opened SharePoint Central Administration on more time and 
1. Clicked on "Manage web applications" 
2. Click on the new web application
3. In the ribbon menu clicked on "Service Connections" button.

You will see the following pop-up menu if you will try to do the same actions:


So this is a default service configuration list when a new application is added to the SharePoint farm and all are ticked by default. So If don't know about that you application pool account should be added to the Managed Metadata service with read permissions you will have the error message "SharePoint Web Services Round Robin Service Load Balancer Event: EndpointFailure " in multiple-server SharePoint environment in the Event Viewer. 

After talking with my colleague with we decided to untick the "Metadata Service Application Proxy" check-box, because they didn't use this service in their web application instead of adding the user (application pool account) to the permissions.

Solution:

1. Add application pool account to the "Permissions" with  at least "Read Access to Term Store"


OR

2. Untick "Metadata Service Application Proxy" checkebox for the web application that do not use this functionality. !!!!! (IIS reset is needed to apply changes)

More info:

Here is a great article that helped me for deep understanding  the root of the problem:

http://blogs.msdn.com/b/dtaylor/archive/2011/02/23/sharepoint-2010-service-application-load-balancer.aspx

Best regards,
Aleks

Tuesday, January 21, 2014

SharePoint 2010: Is web part exist on the page? PowerShell

Hello,

Here is an example of PowerShell function for page to check if the web part exists on it.

function IsWebPartExist($siteUrl, $pageUrl ,$WPName,$WPEmailReport){

  $wpExists = $false
try{
$spSite = Get-SPSite $siteUrl -ErrorAction:Stop
    if($spSite -eq $null){return;}
$spWeb = $spSite.OpenWeb()


  $spWebPartManager = $spWeb.GetLimitedWebPartManager($pageUrl, [System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)

foreach ($webpart in $spWebPartManager.WebParts)
{
   if ($webpart.GetType().Name -eq $WPName)
{
 $wpExists = $true
 return $true
}
}
}
catch{
 $WPEmailReport += New-Object PSObject -Property @{PageURL=$siteUrl;Status="$_.Exception.Message";}
}    
    finally{
$spWeb.Dispose()
$spSite.Dispose()
    }
   return $wpExists
}

Invoke the function

$CurDir = Split-Path -parent $MyInvocation.MyCommand.Definition
 $WPEmailReport = @()

$url = "http://yourpage"

$isSiteWebExists = Get-SPSite $url -ErrorAction:SilentlyContinue

$web = $isSiteWebExists.RootWeb;
$folder = $web.RootFolder;
$isWelcomePageExists = $folder.WelcomePage

$landingPage = $isWelcomePageExists

$isWebPartPDEsist = IsWebPartExist -siteUrl $url -pageUrl $landingPage -WPName "PublishedDocuments" -WPEmailReport $WPEmailReport


if ($isWebPartPDEsist -eq $true)
{ $WPEmailReport +=  New-Object PSObject -Property @{PageURL=$url};}


Write-Host "Writing log files...."
$TimeString = Get-Date -format MM_dd_yyyy__HH_mm
$WPEmailReport | select-object PageURL | Export-csv -path "$CurDir\PDWebPartExist_$TimeString.csv" -notype

Friday, January 17, 2014

Powershell single-object arrays

If function return a single-object arrays you won't have a Count method in Powershell array.Count

  1. A function that returns an array with a single value might not be seen as an array to the code calling it.  Because of rule one, you can still iterate over it, but it won’t have array properties such as Count.
  2. If you want to guarantee that you get an array from a function, wrap the call with @().
Example 1: In this case $allPubPages variable with have type string.

$allPubPages=@()

$allPubPages = GetAllSitePublishingPages -url $url



Example 2 In this case $allPubPages variable will have type array:

$allPubPages=@()

$allPubPages = @(GetAllSitePublishingPages -url $url)



Function: 
function GetAllSitePublishingPages($url){
$pageArray = @()
filter Get-PublishingPages {
    $pubweb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($_)
    $query = new-object Microsoft.SharePoint.SPQuery
    $query.ViewAttributes = "Scope='Recursive'"
    $pubweb.GetPublishingPages($query)
}
 
if($leave){return $pageArray}
try{
get-spweb $url -ErrorAction:SilentlyContinue | Get-PublishingPages |%{
$pageArray +=  $_.Uri.ToString()
}
}
catch{
return $pageArray
}
#write-host $pageArray
return $pageArray
}

Good luck.


Friday, December 27, 2013

SharePoint 2010 Document Property Promotion and Demotion


The Case of the Missing Office Document Properties in SharePoint 2010

Nice article about  Document Property Promotion and Demotion



Property promotion is the functionality in WSS that pulls the document metadata (e.g. Title, Subject, etc) from Office 2003/2007/2010 documents during upload and sets those values to their corresponding column in WSS.  Property demotion is just the opposite, if you update the document properties (like Title) via the WSS UI that property value is written back to the file.  

Basically, with property promotion/demotion, we keep the properties in the document and in WSS in sync.

More info

http://msdn.microsoft.com/en-us/library/office/aa543341(v=office.14).aspx

Wednesday, December 18, 2013

Enable/disable output caching in SharePoint 2010 using PowerShell script

A SharePoint Publishing site can also be configured to make use of the ASP.NET output cache to store rendered ASPX pages in memory. You can only make use of this cache when the Publishing features are activated on your site collection. This means that only publishing pages can be cached.
When a Publishing page is first requested, SharePoint assembles the page dynamically: it first fetches the page layout from the content database and then fetches the contents of the page. The page layout comes from the content database; the data on the page can be data coming from the content database or files already cached in the BLOB cache. Once the page is assembled, the resulting HTML stream is stored in the output cache. On a next request the HTML is served from the cache: the controls are not created, the page life cycle doesn’t start, and no code-behind is executed. The only things that are not covered by the output cache, are images and other resources like JavaScript files and CSS files. These need to be handled by other caching mechanisms.
This way pages are served more quickly and CPU load is reduced on the web front-end servers and on the SQL Server content database because pages won’t have to be reassembled on each request. Output caching is considered as one of the most performance improving techniques.

Here a a link to original article about Output Caching.


Here is a PowerShell script to enable or disable on output caching in SharePoint 2010 site:

$TotalCount = 0;
$UpdatedCount = 0;
#Initiate array for output export
$Results=@();


function SetCacheSettingsOnSite($site)
{
       if ([Microsoft.SharePoint.Publishing.PublishingWeb]::IsPublishingWeb($site.RootWeb))
       {
              $cacheSettings = new-object Microsoft.SharePoint.Publishing.SiteCacheSettingsWriter($site.Url);
        if($disable -eq $true)
             {
                     if($cacheSettings.EnableCache -eq $true)
                     {
                           $cacheSettings.EnableCache = $false;
                           $cacheSettings.SetAnonymousPageCacheProfileId($site,1);
                           $cacheSettings.SetAuthenticatedPageCacheProfileId($site,1);
                           $cacheSettings.Update()
                           if($output -eq $true) {Write-Host "De-activated output cache on site $site"}
                           Set-Variable -Name UpdatedCount -Value ($UpdatedCount+1) -Scope 1;
                           $OutputLog = New-Object PSObject -Property @{SiteUrl=$site.Url;Status="Deactivated";Time=Get-Date}; Set-Variable -Name Results -Value ($Results+=$OutputLog) -Scope 1;
                     }
                     else
                     {
                           if($output -eq $true) {Write-Host "Output cache already de-actived on site $site"}
                           $OutputLog = New-Object PSObject -Property @{SiteUrl=$site.Url;Status="Skipped. Already De-Activated";Time=Get-Date}; Set-Variable -Name Results -Value ($Results+=$OutputLog) -Scope 1;
                     }
              }
              else
              {
             
                     if($cacheSettings.EnableCache -eq $false)
                     {
                           $cacheSettings.EnableCache = $true;     
                           $cacheSettings.EnableDebuggingOutput = $true;
                           $cacheSettings.SetAnonymousPageCacheProfileId($site,1);
                           $cacheSettings.SetAuthenticatedPageCacheProfileId($site,4);
                           $cacheSettings.SetFarmCacheFlushFlag();                      
                           $cacheSettings.Update();
                           if($output -eq $true) {Write-Host "Activated output cache on site $site"}
                           Set-Variable -Name UpdatedCount -Value ($UpdatedCount+1) -Scope 1;
                           $OutputLog = New-Object PSObject -Property @{SiteUrl=$site.Url;Status="Activated";Time=Get-Date}; Set-Variable -Name Results -Value ($Results+=$OutputLog) -Scope 1;
                     }
                     else
                     {
                           if($output -eq $true) {Write-Host "Output cache already active on site $site"}
                           $OutputLog = New-Object PSObject -Property @{SiteUrl=$site.Url;Status="Skipped. Already active";Time=Get-Date}; Set-Variable -Name Results -Value ($Results+=$OutputLog) -Scope 1;
                     }
              }
       }
       $site.Dispose();
}

$Results | select-object SiteUrl, Status, Time | Export-csv -path "CachingActivationResults.csv" -notype
Write-Host "Done. Updated:$UpdatedCount  Total Processed:$TotalCount"  -ForegroundColor Green

$rootSite.Dispose()


Thursday, November 21, 2013

ERROR : Exception calling "AddWebPart" with "3" argument(s): "The file is not checked out. You must first check out this document before making changes


When you try to add web part on the page using  SPLimitedWebPartManager AddWebPart function you get the following error:

ERROR : Exception calling "AddWebPart" with "3" argument(s): "The file is not checked out. You must first check out this document before making changes



The error appears when  the page is checked out AFTER the SPLimitedWebPartManager is 
retrieved.

....................................................

$spWebPartManager = $spWeb.GetLimitedWebPartManager($pageUrl, [System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)

$page.CheckOut()
....................................................

So the page must be checked out BEFORE the SPLimitedWebPartManager is retrieved.

$page.CheckOut()


$spWebPartManager = $spWeb.GetLimitedWebPartManager($pageUrl, [System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)