Showing posts with label SharePoint. Show all posts
Showing posts with label SharePoint. Show all posts

Tuesday, March 28, 2023

Powershell script to export all SEWP and CEWP content to CSv and text files

A working example to export all script editors and content editors content from an on-prem site collection. Handy for a SharePoint onprem to online migration project 


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

 

#Configuration parameters

$webApp = Get-SPWebApplication "http://yourwebappurl"


$csvFile = "<path to export folder>\pageswitheditors.csv"


$SiteURL = "http://yoursitecollurl"

$ReportOutput="<path to export folder>\pageswitheditors.csv"

 

$ResultCollection = @()

 

#Get All Subsites in a site collection and iterate through each

$Site = Get-SPSite $SiteURL

$counter=0;

ForEach($Web in $Site.AllWebs)

{

    write-host Processing $Web.URL

    # If the Current Web is Publishing Web

    if ([Microsoft.SharePoint.Publishing.PublishingWeb]::IsPublishingWeb($Web))

    {

        #Get the Publishing Web

        $PubWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($Web)

                   

        #Get the Pages Library

        $PagesLib = $PubWeb.PagesList

     }

     else

     {

        $PagesLib = $Web.Lists["Site Pages"]

     }            

        #Iterate through all Pages 

        foreach ($Page in $PagesLib.Items | Where-Object {$_.Name -match ".aspx"})

        {

            $PageURL=$web.site.Url+"/"+$Page.File.URL

            $WebPartManager = $Page.File.GetLimitedWebPartManager([System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)

                  #Get All Web Parts data

            foreach ($WebPart in $WebPartManager.WebParts)

            {

             if ($webPart.GetType().Name -eq "ContentEditorWebPart" -or $webPart.GetType().Name -eq "ScriptEditorWebPart")

             {

             $counter+=1

             $content = $WebPart.Content.InnerText -replace "`n", " "

                $Result = New-Object PSObject

                $Result | Add-Member -type NoteProperty -name "Site URL" -value $web.Url

                $Result | Add-Member -type NoteProperty -name "Page URL" -value $PageURL

                $Result | Add-Member -type NoteProperty -name "Web Part Title" -value $WebPart.Title

                $Result | Add-Member -type NoteProperty -name "Web Part Type" -value $WebPart.GetType().ToString() 

                 $Result | Add-Member -type NoteProperty -name "Web Part Content" -value "content$counter.txt" 

 

                $ResultCollection += $Result

               

                 $obj = New-Object -TypeName PSObject -Property @{

    Content = $content

}

$obj |Export-csv   "<path to export folder>\content$counter.txt" -notypeinformation -Encoding UTF8


         }}}

}

#Export results to CSV

$ResultCollection | Export-csv $ReportOutput -notypeinformation  -Encoding UTF8


Powershell Script to export all active workflows in a web application to a CSV file

Here is a working example of exporting a list of all active workflows in a web application 


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue


$webApp = Get-SPWebApplication "http://your webapp url"


$csvFile = "<path to export folder>\workflows-active.csv" 


$results = @()


foreach ($site in $webApp.Sites) {

    foreach ($web in $site.AllWebs) {

     if ($web.WorkflowAssociations.Count -gt 0) {

            $webObj = New-Object PSObject -Property @{

                "Title" = $web.Title

                "Url" = $web.Url

                "Workflows" = $web.WorkflowAssociations| where {$_.Enabled -eq $true} | Select-Object -ExpandProperty Name

            }

            $results += $webObj

        }

        # Get all the lists in the web

        $lists = $web.Lists

        foreach ($list in $lists) {

            # Get all the workflow associations for the list

            $workflowAssociations = $list.WorkflowAssociations | where {$_.Enabled -eq $true}

            foreach ($workflowAssociation in $workflowAssociations) {

                # Create an object to store the workflow details

                $workflowObj = New-Object PSObject -Property @{

                    "SiteCollection" = $web.Site.Url

                    "Web" = $web.Title

                    "List" = $list.Title

                    "ListURL" = $web.Url + "/" + $list.RootFolder.Url

                    "WorkflowName" = $workflowAssociation.Name

                    "IsActive" = $workflowAssociation.Enabled

                }

                # Add the workflow object to the results array

                $results += $workflowObj

            }

        }

        $web.Dispose()

    }

    $site.Dispose()

}


$results | Export-Csv -Path $csvFile -NoTypeInformation


Friday, February 10, 2017

SharePoint Distributed Cache Issue

All of a sudden my farm started throwing Distributed cache errors. My ULS filled with below log when I refreshed a page 
Unexpected Exception in SPDistributedCachePointerWrapper::InitializeDataCacheFactory for usage 'DistributedLogonTokenCache' - Exception 'Microsoft.ApplicationServer.Caching.DataCacheException: ErrorCode<ERRCA0009>:SubStatus<ES0001>:Cache referred to does not exist. Contact administrator or use the Cache administration tool to create a Cache.   
 at Microsoft.ApplicationServer.Caching.DataCache.ThrowException(ResponseBody respBody, RequestBody reqBody)   
 at Microsoft.ApplicationServer.Caching.DataCacheFactory.GetCacheProperties(RequestBody request, IClientChannel channel)   
 at Microsoft.ApplicationServer.Caching.DataCacheFactory.GetCache(String cacheName)   
 at Microsoft.SharePoint.DistributedCaching.SPDistributedCachePointerWrapper.InitializeDataCacheFactory()'.

I tried steps below and walla!

1) Go to Manage Services on Server in Central Administration and stop Distributed Cache on all Application Servers and WFEs

2) Open SharePoint Management Shell and run following commands

       a) Use-CacheCluster
       b) Get-CacheCluster | Select CacheName
Above commands should return list of 10 cache types 

CacheName            
---------          
DistributedAccessCache_<ur farm ID>
DistributedActivityFeedCache_<ur farm ID>
DistributedActivityFeedLMTCache_<ur farm ID>
DistributedBouncerCache_<ur farm ID>
DistributedDefaultCache_<ur farm ID>
DistributedLogonTokenCache_<ur farm ID>
DistributedSearchCache__<ur farm ID>
DistributedSecurityTrimmingCache_<ur farm ID>
DistributedServerToAppServerAccessTokenCache_<ur farm ID>
DistributedViewStateCache_<ur farm ID>

Incase you get nothing - you need to setup DistribtedCache again so move on to step 7

In case above list is returned move on to step 3

3) Run following command 
                   Remove-SPDistributedCacheServiceInstance

4) to check of the cache instance is removed successfully 
                   Get-Cache | Select CacheName
this should return below error

Get-Cache : ErrorCode<ERRCMS0006>:SubStatus<ES0001>:Error while loading the
provider "SPDistributedCacheClusterProvider". Check HKEY_LOCAL_MACHINE ->
SOFTWARE\Microsoft\AppFabric\V1.0\Providers\AppFabricCaching ->
SPDistributedCacheClusterProvider....

5) Now add new instance of DistributedCacheService by running following command
                                  a) Add-SPDistributedCacheServiceInstance
                                 b)  Restart-CacheCluster
this should return below

HostName : CachePort                      Service Name             Service Status            Version
                                                                                       Info
--------------------                    ------------                    --------------         ----------
<host server name>:<port>      AppFabricCachingService            UP                           3
                                                                                      [3,3][1,3]

6) check if cache is available now:
                    Get-Cache | Select CacheName
should give output as below

CacheName            
---------          
DistributedAccessCache_<ur farm ID>
DistributedActivityFeedCache_<ur farm ID>
DistributedActivityFeedLMTCache_<ur farm ID>
DistributedBouncerCache_<ur farm ID>
DistributedDefaultCache_<ur farm ID>
DistributedLogonTokenCache_<ur farm ID>
DistributedSearchCache__<ur farm ID>
DistributedSecurityTrimmingCache_<ur farm ID>
DistributedServerToAppServerAccessTokenCache_<ur farm ID>
DistributedViewStateCache_<ur farm ID>


 7) No output on running step 2) indicates that you need to setup Distributed Cache altogether

to do so first determine your farm ID 
         Get-SPFarm | Select Id 
get the output and run the following command 
       New-Cache -CacheName DistributedLogonTokenCache__<ur farm ID>



8) check if cache is available now:
                    Get-Cache | Select CacheName
should give output as below

CacheName            
---------          
DistributedAccessCache_<ur farm ID>
DistributedActivityFeedCache_<ur farm ID>
DistributedActivityFeedLMTCache_<ur farm ID>
DistributedBouncerCache_<ur farm ID>
DistributedDefaultCache_<ur farm ID>
DistributedLogonTokenCache_<ur farm ID>
DistributedSearchCache__<ur farm ID>
DistributedSecurityTrimmingCache_<ur farm ID>
DistributedServerToAppServerAccessTokenCache_<ur farm ID>
DistributedViewStateCache_<ur farm ID>


 Hope this helps


Tuesday, May 31, 2016

FileNet SharePoint Integration - I

Hi Readers,
I had been away for a while and now planning to write some post based on the work I have been doing in this period. My upcoming post will be related to SharePoint 2013 development, workflows, SharePoint tweaks and fixes and majorly FileNet integration to SharePoint 2013 using FileNet P8 API and FileNet Connector for SharePoint. All my posts will be in the context of Integration of FileNet to SharePoint. You can get complete information on FileNet at IBM Support Knowledge Center.
Let's start with the introduction to FileNet and some basic operations using FileNet P8 API:
  • Introduction to FileNet Content Manager
  • FileNet P8 API Basic Concepts 
  • Connect to FileNet Repository
  • A single repository for enterprise content to provide centralized access and better control.
  • Document management services and application development support to streamline content management and delivery.
  • Delivery of active content in motion for improved business value and reduced costs.
  • Integration with Microsoft SharePoint and Microsoft Office to help increase productivity.
  • Social collaboration and mobile computing support to use the latest technologies in your enterprise content management (ECM) environment." Source: IBM
Documents
Folders
Custom Objects
  •  Example  HTTP://<your FileNet server URL>:<port>/wsi/FNCEWS40MTOM/
  • P8Administrator
  • ECM
      try
      {
       string uri =  GetConfigValue("FileNetServerURL");
          string username = GetConfigValue("FileNetServerAdmin"); 
    //"P8Administrator";
       string password = GetConfigValue("FileNetServerAdminPassword");
     //"Password";
       string objectstorename = GetConfigValue("FileNetObjectStore");
    //ECMStore
       // Get client context.
       IConnection conn = Factory.Connection.GetConnection(uri);
      
     // UsernameToken 
       UsernameCredentials creds = new UsernameCredentials(username, password);
       ClientContext.SetProcessCredentials(creds);
      
       // Get default domain.
       IDomain domain = Factory.Domain.FetchInstance(conn, null, null);
       // Get object stores for domain.
       IObjectStore os = Factory.ObjectStore.FetchInstance(domain, objectstorename, null);
       return os;
     }
     catch (Exception ex)
     { 
      return null;
     }

Introduction to FileNet Content Manager:
"Document management with IBM® FileNet® Content Manager helps you meet the growing challenge of managing enterprise content with greater speed, efficiency, and accuracy. FileNet Content Manager is a document management engine that combines enterprise content, security and storage features with ready-to-use workflow and process management capabilities.
FileNet Content Manager features include:

FileNet P8 API Basic Concepts:
 FileNet provides an extensive API for Java and C# to programmatically handle operations in FileNet Content Manager. P8 API allows applications to interact to FileNet for CRUD operations as well as Management of properties, classes, subscriptions, Permissions etc. 
  
The .NET framework-based API provides a .NET framework-based Common Language Runtime (CLR)-compliant API for accessing the full capability of Content Engine. The API accepts username and password credentials for authentication. The .NET framework-based API works only with the WSI Listener.
Following are some basic concepts of FileNet Content Manager.

Object Store:
Refers to the FileNet repository. All documents, folders, custom objects are referred to as objects in FileNet so Object store is actually a container for those objects. Every object store has a database that can comprise one or more storage areas. Objects in FileNet are further classified into versionable and non-versionable objects 

Documents are versionable objects and have metadata. A document contains content elements. A file of any type is an example of a document.

A folder is a container of objects(documents, folders etc. ). It is a non-versionable object and has metadata.

Custom objects are non-versionable objects that can contain metadata but no content. you can relate them to a database table row.

Connect to FileNet Repository:
Following is a sequence of how you can interact with FileNet through P8 API.
 You require FileNet repository details as mentioned below to connect to FileNet Content Manager through API

1. FileNet Repository URL:
2. Administrator User Name:
3. Administrator Password: 
4.  Object Store Name: 

Code Example to Connect to FileNet is as Follows:

public static IObjectStore Connect()
   // Set connection parameters; substitute for the placeholders.
   //"http://filenetserverurl:9082/wsi/FNCEWS40MTOM/";
}


Note: You must install Microsoft WSE to connect to FileNet on Windows Server 2008 R2, Win Server 2012 if FileNet server URL starts with HTTP:// else it will fail to connect since WCF only supports https:// connections

Monday, March 17, 2014

Reset SharePoint Config Cache

  The   path for the Configuration Cache under Windows Server 2008 is: C:\ProgramData\Microsoft\SharePoint\Config\<GUID>


Stop the Timer service. To do this, follow these steps:
1.      Click Start, point to Administrative Tools, and then click Services.
2.      Right-click SharePoint 2010 Timer, and then click Stop.
3.      Close the Services console.
4.      On the computer that is running Microsoft SharePoint Server 2010 and on which the Central Administration site is hosted, click Start, click Run, type explorer, and then press ENTER.
5.      In Windows Explorer, locate and then double-click the following folder: C:\ProgramData\Microsoft\SharePoint\Config\GUID
Notes
1.      The GUID placeholder specifies the GUID folder. There may be more than one of these.
2.      The ProgramData folder may be hidden. To view the hidden folder, follow these steps:
·         On the Tools menu, click Folder Options.
·         Click the View tab.
·         In the Advanced settings list, click Show hidden files and folders under Hidden files and folders and then click OK.
3.      (You can also simply type this directly in the path if you do not want to show hidden files and folders.)
4.      Back up the Cache.ini file. (Make a copy of it. DO NOT DELETE THIS FILE, Only the XML files in the next step)
5.      Delete all the XML configuration files in the GUID folder (DO NOT DELETE THE FOLDER). Do this so that you can verify that the GUID folders content is replaced by new XML configuration files when the cache is rebuilt.
Note When you empty the configuration cache in the GUID folder, make sure that you DO NOT DELETE THE GUID FOLDER AND THE CACHE.ini file that is located in the GUID folder.
If Cache .ini is Missing
6.      Double-click the Cache.ini file.
7.      On the Edit menu, click Select All.
8.      On the Edit menu, click Delete.
9.      Type 1, and then click Save on the File menu. (Basically, when you are done, the only text in the config.ini file should be the number 1)
10.  On the File menu, click Exit.
11.  Start the Timer service. To do this, follow these steps:
·         Click Start, point to Administrative Tools, and then click Services.
·         Right-click SharePoint 2010 Timer, and then click Start.
·         Close the Services console.
12.  Note The file system cache is re-created after you perform this procedure. Make sure that you perform this procedure on all servers in the server farm.
13.  Make sure that the Cache.ini file in the GUID folder now contains its previous value. For example, make sure that the value of the Cache.ini file is not 1.
14.  Check in the GUID folder to make sure that the XML files are repopulating. This may take a bit of time.


  If Cache.ini is missing under   “C:\ProgramData\Microsoft\SharePoint\Config\” or is deleted by mistake, perform the following Steps:
Now the mission is to get my Timer Job up and functioning. So I took the back-door approach to create GUID folder with Cache.ini file. Here are the steps I performed to get the config GUID of SharePoint.
1.      Stop the SharePoint 2010 Timer process.
1.      Open Windows Registry Editor
2.      Locate the ConfigDB key. Usually, it must be in this place if you are using SharePoint 2010.[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\14.0\Secure\ConfigDB]
3.      You will see String Values entries for
4.      DSN: Connection string for your configuration database.
5.      Id: GUID of SharePoint configuration database. Copy this GUID.
6.      Goto C:\ProgramData\Microsoft\SharePoint\Config\ folder. (ProgramData folder is hidden, make sure change windows folder options to make it visible to you)
7.      Create a folder and name it as the GUID (that you just copied from Registry).
8.      Go into this folder, create a text file and name it as Cache.ini.
9.      Now edit this Cache.inikey in value 1 Save and close the file.
10.  Start the SharePoint 2010 Timer process.
11.  Do an IIS RESET
12.  Now check all your application pools are up and running. Otherwise, start them manually.