Monday 18 November 2013

Jquery calling Exchange Web Services

I have posted the below Jquery Script which will fetch no.of unread emails by querying the exchange web services

Used the tool to generate the Soap Request Message format that is sent to the exchange web services in the below example - http://soape.codeplex.com/

<script type="text/javascript" >
function GetUnReadEmailCount() {

    var soapPacket = "<?xml version='1.0' encoding='utf-8'?>" +
                      "<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'

xmlns:t='http://schemas.microsoft.com/exchange/services/2006/types'>" +
                        "<soap:Body>" +
                          "<FindItem xmlns='http://schemas.microsoft.com/exchange/services/2006/messages' xmlns:t='http://schemas.microsoft.com/exchange/services/2006/types'

Traversal='Shallow'>" +
                            "<ItemShape>" +
                              "<t:BaseShape>IdOnly</t:BaseShape>" +
                            "</ItemShape>" +
                            "<IndexedPageItemView MaxEntriesReturned='50' Offset='0' BasePoint='Beginning' />" +
                            "<Restriction>" +
                              "<t:IsEqualTo>" +
                                "<t:FieldURI FieldURI='message:IsRead' />" +
                                "<t:FieldURIOrConstant>" +
                                  "<t:Constant Value='false' />" +
                                "</t:FieldURIOrConstant>" +
                              "</t:IsEqualTo>" +
                            "</Restriction>" +
                            "<ParentFolderIds>" +
                              "<t:DistinguishedFolderId Id='inbox' />" +
                            "</ParentFolderIds>" +
                          "</FindItem>" +
                        "</soap:Body>" +
                      "</soap:Envelope>";

    jQuery.support.cors = true;
    jQuery.ajax({
        url: "http://exchange.contoso.local/ews/Exchange.asmx",
        type: "POST",
        dataType: "xml",
        data: soapPacket,
        complete: processResult,
        error: OnError,
        contentType: "text/xml; charset=\"utf-8\""
    });


}

function processResult(xData, status) {
    if (typeof xData.responseText != 'undefined') {
        alert($(xData.responseXML).find("m\\:RootFolder").attr("TotalItemsInView"));
    }
}
</script>

Orphans Object Clean Up in SharePoint

Orphaned Objects are items that do not have any parent or child relationship and remain in the content database uncleaned. When  you perform the Test-SPContentDatabase to validate a content database you might receive errors which provides information about orphans in the content database

These orphaned objects need to be removed on the below situations:
1. Before applying service packs or cumulative updates to the SharePoint servers
2. Before performing a migration from a older version of SharePoint to a newer version.
3. Before reapplying templates or performing any updates to the database.(certain powershell commands would not work when running update scripts on the database.  ex. Applying modification to a Custom Master Page that is already deployed to the sites). The execution of powershell scripts will fail when iterating the tables for fetching or applying update to the data in SharePoint content databases


There are 2 types of Orphan Objects
1. Config Orphans (Orphan Site exist in Configuration Database but does not have any child item in Content Database). Central Admin ->View All Site Collections shows the site info, but the actual site cannot be accessed via browser. 
2. Content Orphans (Orphans include Lists without Parent sites, Documents with no parent document library, Web Parts that does not have an assembly, Web Pages with no Parent Site E.t.c..). Site Collections that are available in content database but not in config db (Will not show in Central Admin -> View All Site Collections page)
  


A.    Config Orphan Object Removal:
Cleaning the config orphan is the easiest one.
Simply detach the content database that has the orphan site from your farm and attach it back. This will refresh and remove the stale entries.

B.     Content Orphan Object Removal
There are 2 ways to remove content orphans from the content database
1. Use SharePoint Health Analyzer
2. Use STSADM or PowerShell Commands

1.      SharePoint Health Analyzer 
(Note : Not recommended in a Production farm as it sometimes might cause SQL Blocking if there are very large content databases)
Go to Central Admin - > Monitoring > Health Analyzer Section > Review Problems and Solutions > Content Database Contain Orphaned Items - Click on the Ribbon Command "Repair Automatically".

2.      Using STSADM Commands

I have provided two scripts to first log the orphans in text file.(STSADM Method)
When you execute the first script, this will list out the orphaned objects in text file
The second one will delete the orphans.
This method will delete only when you have orphan sites in one content database.

Modify the site collection name and database name related to the STSADM command line. 


To Check Orphans (Store the below content in a .Bat file)

echo on
rem ***  set local environment variables
setlocal
set LogFile="D:\LogOrphans.txt"
c:
cd "\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\BIN" >> %LogFile%
Echo "List Orphans ...." >> %LogFile%
stsadm.exe -o databaserepair -url https://contoso.com/sites/sitecollection -databasename Content10_ContentDB  >> %LogFile%

Echo "************** E N D*********" >> %LogFile%
pause

PowerShell Command to check orphans:

$contentdb = Get-SPContentDatabase | Where-Object {$_.Name –match "Content_Contentdb"}
test-spcontentdatabase $contentdb -showrowcounts | Format-Table -Wrap | Out-File -FilePath c:\testcontent.txt

To Delete Orphans(Store the below content in a .Bat file):

echo on
rem ***  set local environment variables
setlocal
set LogFile="D:\LogOrphans.txt"
c:
cd "\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\BIN" >> %LogFile%
Echo "List Orphans ...." >> %LogFile%
stsadm.exe -o databaserepair -url https://contoso.com/sites/sitecollection -databasename Content10_ContentDB -deletecorruption  >> %LogFile%

Echo "************** E N D*********" >> %LogFile%
pause


The Ouput in log File below:
"List Orphans ...." 
<OrphanedObjects Count="43">
<Orphan Type="SPWeb" Name="Contoso Sub Site0" Id="{B779C412-8AE4-4D3B-877C-BFB41F94E735}" Deleted="Yes" />
  <Orphan Type="SPWeb" Name="Contoso Sub Site1" Id="{46F35180-7758-4ED5-8C51-3E7E3D1D5441}" Deleted="Yes" />
  <Orphan Type="SPWeb" Name="Contoso Sub Site10" Id="{252EAB85-7535-4141-8BFB-2982BCACE095}" Deleted="Yes" />
  <Orphan Type="SPWeb" Name="Contoso Sub Site11 (en)" Id="{9F5B2BCA-2B4E-4E01-B3C4-401A9C078C25}" Deleted="Yes" />
  <Orphan Type="SPWeb" Name="Contoso Sub Site12 (fr)" Id="{5E9342E3-2BF1-4692-ACB8-A900307992F2}" Deleted="Yes" />
<Orphan Type="SPList" Id="{1F90BF81-1965-460E-8F46-85655BEFB306}" SiteId="{5E9342E3-2BF1-4692-ACB8-A900307992F2}" />

</OrphanedObjects>
"************** E N D*********" 
Note:
In some scenarios certain orphan object might not get removed, but still show that it is removed and will remain in the database. 
To validate this, run the below command to list the objects in the content database and cross verify with the log files

stsadm -o enumallwebs -databasename Content10_ContentDB 

Output of the above Stsadm command

<Sites Count="2">
  <Site Id="9F5B2BCA-2B4E-4E01-B3C4-401A9C078C25" OwnerLogin="Domain\username" InSiteMap="False">
    <Webs Count="1">
      <Web Id="064d8e7b-b349-4693-bd67-dcefed3bf466" Url="/sites/contososubsite11" LanguageId="1033" TemplateName="STS#0" TemplateId="1" />
    </Webs>
  </Site>
  <Site Id="f440114b8-79d9-32f6-87bf-4geddf2ad9b6" OwnerLogin="Domain\username" InSiteMap="True" HostHeader="www.contoso.com">
    <Webs Count="1">
      <Web Id="12348e7b-c456-4693-bd67-efdegd3bf466" Url="/" LanguageId="1033" TemplateName="STS#0" TemplateId="1" />
    </Webs>
  </Site>
</Sites>

If the property InSiteMap=False then the site collection is an orphan.

Final Validation:
If you still have the orphaned objects listed, then try the below options and then validate again with the log file
1. Disconnect the database and reconnect the database so that the references will be removed.
2. Try removing the corrupted list or item using the sharepoint designer tool.
3. Try deleting the site using below Stsadm commands
stsadm -o deletesite -force -url http://contoso.com/sites/contososubsite11 -databaseserver ds -databasename contentdb1
(or)
stsadm -o deletesite -force -siteid e2a114b8-80c9-41f6-87bf-3feddf2ad9b6 -databaseserver ds -databasename contentdb1

4.  Try running the below Powershell commands
(Get-SPContentDatabase <DB Name>).Repair($true)
Ex:

(Get-SPContentDatabase Collab_ContentDB).Repair($true)



Monday 16 July 2012

ProfileStore to ContentDB Sync

Query below to identify list of Webapps excluded from Sync table in configDB

SELECT CAST(properties AS XML)AS Props
  FROM[SP_Config].[dbo].[Objects] WITH (NOLOCK)where Properties LIKE'%m_WebApplicationSyncExcludeList%'