Jun 202017
 
Please Share...

What’s a Heap?

Before understanding HeapCorruption here’s a quick review of the Heap. The HeapCreate function creates a private heap object from which the calling process can allocate memory blocks by using the HeapAlloc function. HeapCreate specifies both an initial size and a maximum size for the heap. The initial size determines the number of committed, read/write pages initially allocated for the heap. The maximum size determines the total number of reserved pages. These pages create a contiguous block in the virtual address space of a process into which the heap can grow. Additional pages are automatically committed from this reserved space if requests by HeapAlloc exceed the current size of committed pages, assuming that the physical storage for it is available. Once the pages are committed, they are not decommitted until the process is terminated or until the heap is destroyed by calling the HeapDestroy function.

We don’t directly interact with this function but internally the boiler plate application code does this, for e.g. CRT heap. When we use ‘new’, ‘malloc’, internally somewhere there’s a call happening to HeapAlloc. When we call ‘delete’ or ‘free’ internally somewhere there’s a call happening to HeapFree.

So what’s HeapCorruption?

Any inconsistency that’s caused to a process heap because of application code can be called a HeapCorruption. For e.g. Since most of the time the heap memory blocks are in the form of a linked list, linked to each other, so if we end up overwriting these links then we call that a heap corruption because the heap cannot be traversed anymore from one linked list node to the other.

We could see an application crashing with following error…

0:143> .lastevent
Last event: 616c.a550: Unknown exception – code c0000374 (first/second chance not available)
debugger time: Tue Jun 13 12:41:19.531 2017 (UTC – 5:00)

0:143> !error c0000374
Error code: (NTSTATUS) 0xc0000374 (3221226356) – A heap has been corrupted.

But in my case even though application crashed due to c0000374 and when I check the reason for HeapCorruption, I got the following…

Error type: HEAP_FAILURE_INVALID_ARGUMENT

So essentially the heap is not corrupted but we passed an invalid argument for heap free function hence this failure. So how do I verify that this is indeed the reason? So, we pick up the address that was passed on to HeapFree function and then analyze it using the !address command…

0:143> !address 0x0000003c`5cec97a8

Usage: Stack
Base Address: 0000003c`5ceae000
End Address: 0000003c`5ced0000
Region Size: 00000000`00022000 ( 136.000 kB)
State: 00001000 MEM_COMMIT
Protect: 00000004 PAGE_READWRITE
Type: 00020000 MEM_PRIVATE
Allocation Base: 0000003c`5ce50000
Allocation Protect: 00000004 PAGE_READWRITE
More info: ~143k
Content source: 1 (target), length: 6858

If we look at above output, usage shows as stack memory, which should never be freed via Heap functions but instead they’re automatically released at the end of usage scope. Lets now look at another address which is located on the Heap…

0:143> !address 0x0000003c`6acbfc00

Usage: Heap
Base Address: 0000003c`6a930000
End Address: 0000003c`6af17000
Region Size: 00000000`005e7000 ( 5.902 MB)
State: 00001000 MEM_COMMIT
Protect: 00000004 PAGE_READWRITE
Type: 00020000 MEM_PRIVATE
Allocation Base: 0000003c`6a220000
Allocation Protect: 00000004 PAGE_READWRITE
More info: heap owning the address: !heap 0x3c74e70000
More info: heap segment
More info: heap entry containing the address: !heap -x 0x3c6acbfc00

Content source: 1 (target), length: 257400

The above memory block is owned by a heap hence this can be freed via HeapFree Windows API and we should not get the HEAP_FAILURE_INVALID_ARGUMENT error. The error  ‘HEAP_FAILURE_INVALID_ARGUMENT’ can be further proved by following output from an internal extension command output…

**************************************************************
*                                                            *
*                    HEAP ERROR DETECTED                     *
*                                                            *
**************************************************************

Details:

Heap address: 0000003c74e70000
Error address: 0000003c5cec97a8
Error type: HEAP_FAILURE_INVALID_ARGUMENT

Details: The caller tried to a free a block at an invalid (unaligned) address.

Please Share...
Jun 132017
 
Please Share...

What’s a SearchCenter?

A Search Center site, or Search Center, provides an interface for users to submit search queries and view search results. A Search Center site is the top-level site of a site collection that a farm administrator creates by using the Enterprise Search Center template or Basic Search Center template. Sample search center screenshot…

Sample SearchCenter Shot

Sample SearchCenter Shot


How to Create a Search Center Site Collection… (from MSDN)

  • Verify that the user account that is performing this procedure is a member of the Farm Administrators group.
  • On the home page of the Central Administration website, in the Application Management section, click Create site collections.
  • On the Create Site Collection page, do the following:
    • In the Web Application section, select a web application to contain the new site collection. To use a web application other than the one that is displayed, click the web application that is displayed, and then click Change Web Application.
    • In the Title and Description section, in the Title box, type the name for the new Search Center site. Optionally, type a description in the Description box.
    • In the Web Site Address section, for the part of the URL immediately after the web application address, select /sites/, or select a managed path that was previously defined, and then type the final part of the URL.

      Note the address of the new Search Center for future reference.

    • In the Template Selection section, do the following:
      • In the Select the experience version drop-down list, select 2013 to create a Search Center site that provides the SharePoint Server 2013 user experience, or select 2010 to create a Search Center site that provides the SharePoint 2010 Products user experience.

        For more information, see Search user interface improvements in What’s new in search in SharePoint Server 2013.

      • In the Select a template subsection, click the Enterprise tab, and then do one of the following:
        • If you are using SharePoint Foundation 2013, select the Basic Search Center template.
        • Otherwise, if you are using SharePoint Server 2013, select the Enterprise Search Center template.
    • In the Primary Site Collection Administrator section, in the User name box, type the user name of the primary site collection administrator for this site collection in the form domain\user name.
    • (Optional) In the Secondary Site Collection Administrator section, type the user name of a secondary site collection administrator in the form domain\user name.
    • In the Quota Template section, select No Quota.

      A Search Center site is not intended to be a data repository. Therefore, you do not have to select a quota template.

    • Click OK.
  • On the Top-Level Site Successfully Created page, click the link to the Search Center site that you created.

How to configure the Global SharePoint SearchCenter URL?

Once this site is created we need to tell SharePoint SSA to use this site to submit search queries and view search results. Please note that even UPA uses this SearchCenter for user profile look up so it is important that we set this up the right way to be consumed by UPA as well. From what I know there are couple of ways to do this.

Via PowerShell

$ssa = Get-SPEnterpriseSearchServiceApplication
$ssa.SearchCenterUrl = “SearchCenterURL/pages”
$ssa.Update()
iisreset

Note that you might have to IISReset after this. If you’re doing this via PowerShell I’ve noticed that change will take effect faster than via UI.

Via UI

Open search service application (SSA). Click on value of “Global Search Center URL” to enter new URL….

You should see a popup similar to following dialog popup. Enter new search center URL here.

How to configure the SharePoint SearchCenter URL for a site/site collection?

Please note that above is for global search center URL but you can have site collection or site level search center URL which will override the global search center settings from what I know so far. For setting site collection level SearchCenter URL, access Site Settings->Site Collection Administration->Search Settings, you should see following popup…

For setting site level SearchCenter URL access Site Settings->Search->Search Settings, a dialog similar to the one above should pop up. Once you’ve filled out necessary values you’re good to go.

SearchCenter setting for UPA

So if SearchCenter is not setup, my site settings for your UPA service application will be empty, but if you set it via above powershell or via UI you should following empty field get populated, manually populating this field doesn’t stick.

Once the following PowerShell executes, we see following screenshot now…

$ssa=Get-SPEnterpriseSearchServiceApplication
$ssa.SearchCenterUrl=”searchcenterurl/pages”
$ssa.Update()
iisreset

This time the field is filled out, so when you’re viewing user profile and when clicking on user name and other things pertaining to a user you’ll land on the above SearchCenter page.

‘/Pages’ is important

Remember to append /Pages to the end of the SearchCenter URL. Reason being if you browse to the SearchCenter site and look at SiteContents. You’ll see a pages library which contains all the pages you’ll see as part of the SearchCenter. So if ‘/pages/’ is not appended to the end of the URL you’re bound to get a 404.

Ideally a SearchCenter URL should look as follows: http://sp:port/sites/searchcenter/pages

References…

https://msdn.microsoft.com/hu-hu/jj851144

Please Share...
Jun 242016
 
Please Share...

What’s ServerRender?

ServerRender is a property of a webpart which disables client-side rendering for a webpart. You’ll lose some cool features of a webpart once you enable this feature for e.g.

  1. Inline editing of a list item, or in other words “Quick Edit”.
  2. Look and feel of the list changes to the traditional view, from a excel like view.

But this feature is quite handy when it comes to workaround some bugs related to client-side JavaScript.

 

How do we enable this feature via SharePoint UI?

  1. GoTo Site settings->Edit page
    clip_image001
  2. Select list web part and then select WEB PART on the ribbon bar, then select the list web parts “Web Part Properties” on this ribbon.
    clip_image003
  3. On the properties window that pops out on the right side, enable “Server Render”, at the bottom of this screenshot…
    clip_image005

 

How do we enable this feature via PowerShell?

I had to dig around a bit to figure this out. Here’s how we do this via PowerShell…

#Web URL, change to your web's URL
$WebUrl = "http://sp/sites/TaskList"
#ListName, change to your list's name
$ListName = "MyTasks"
$web = Get-SPWeb $webUrl

#Get all web parts in this collection, please note this is for default view, if you've got other views please use URL for that view
$WebParts = $web.GetWebPartCollection($web.Lists[$ListName].DefaultViewUrl, [Microsoft.SharePoint.WebPartPages.Storage]::Shared)
#Dump names of all web parts on this page
$WebParts.DisplayName

#Assuming you just have one web part on this page.
$WebParts[0].ServerRender=$true
$WebParts.SaveChanges($WebParts[0].ViewGuid)

$web.Dispose()
Please Share...
Sep 232015
 
Please Share...
Introduction

I’ve been working on a case where customer accidently deleted a bunch of timer jobs. He came to us with a question on how to restore the timer jobs back. We found a way to restore the timer jobs but just a few of them. So if the timer jobs are out of the box (OOB) jobs we can restore them in this manner. If there are other timer jobs you’ll have to just re-deploy the timer job solution again.

Farm Level Timer Jobs

From code I see that SPTimerService.EnsureDefaultJobs should restore the following farm level timer jobs…

job-config-refresh
job-ceip-datacollection
job-delete-job-history
job-password-management
job-app-installation
SPAppStatisticsProviderJobDefinition
job-autohosted-appinstance-counter
job-admin-product-version
job-timer-recycle
job-timer-locks
job-spapp-statequery
job-internalspapp-statequery
Web Application Level Timer Jobs

There’s another one SPWebApplication.EnsureDefaultJobs which restores following web application level timer jobs.

job-immediate-alerts
job-dead-site-delete
job-diskquota-warning
job-change-log-expiration
job-recycle-bin-cleanup
job-workflow-autoclean
job-workflow-failover
job-workflow
job-site-deletion
job-audit-log-trimming
job-solution-resource-usage-log
job-solution-resource-usage-update
job-solution-daily-resource-usage
job-upgrade-workitems
job-filefragments-cleanup
job-storage-metrics-processing
job-create-upgrade-eval-sites
job-delete-upgrade-eval-sites
job-upgrade-sites
Sample Script

So the question is how to execute these functions via PowerShell…

# Ensures the default farm level timer job definitions exist
Add-PSSnapin Microsoft.Sharepoint.Powershell
$farm = Get-SPFarm
$farm.TimerService.EnsureDefaultJobs();

#Ensures the default timer job definitions exist for the specified web application
$webapp = Get-SPWebApplication http://webapp/
$webapp.EnsureDefaultJobs();

Thanks to my colleague Stephen Woodard and Trevor Barkhouse for pointing me to this public function.

Disclaimer

As always please make sure you test this out well before implementing this in production.

Please Share...
Sep 222015
 
Please Share...

Issue

Just be careful with the SharePoint 2013 August 2015 CU. One of the security fixes in this cumulative update package has a bug: https://support.microsoft.com/en-us/kb/3085501. Because this is a security fix most companies will push this fix to their servers.

The bug pops up when you try to attach a file to a list item or a calendar item. Here’s how the error message will look like…

Message from webpage
===================================================
File names can’t contain the following characters: &”?<>#{}%~/\
===================================================
<<Ok>>

Attaching a file to a list item is a feature that is rarely used so I guess customer’s affected will be just a minority. Microsoft is planning to fix this issue in October CU.

Workaround

There are some workarounds listed in below blog link. Please make sure you back up the JavaScript files before modifying it.
http://thesharepointfarm.com/2015/08/august-2015-cu-error-file-names-cant-contain-the-following-characters/

Another workaround is to do the following…

  1. Create the list item without adding any attachments
  2. Go back to the list and select the list item you created in item 1.
  3. Ribbon->Items->Attach File and provide the attachment.

This will work for list items, but I’m not sure if this will work for calendar items.

Please Share...
Aug 142015
 
Please Share...

In this post we’ll be discussing on how to manipulate strings using PowerShell. PowerShell comes with the following string manipulation operators…

  • split – case sensitive split
  • isplit – case insensitive split
  • csplit – case sensitive split
  • join – joins an array into one string
  • replace – case sensitive split
  • ireplace – case insensitive split
  • creplace – case sensitive split
Split Demo Using Split Function Call
#store comma delimited wild animals list into a string
$wildanimals = "Tiger,Lion,Elephant,Bear,Fox,Jackal,Hyena"
#split the string using Split function based on ","
$wildanimals.Split(",")
Output
========
Tiger
Lion
Elephant
Bear
Fox
Jackal
Hyena
Split Demo Using -Split Operator
#split array using -split operator
$wildanimals -split ","
Output
========
Tiger
Lion
Elephant
Bear
Fox
Jackal
Hyena
#split into three strings, this will leave the third string unsplit
$wildanimals -split ",", 3
Output
========
Tiger
Lion
Elephant,Bear,Fox,Jackal,Hyena
#replace all "," with " "
$wildanimals = ($wildanimals -replace ",", " ")
#alternate syntax, with no split criteria the default is to use " " as split criteria
-split $wildanimals
#restore "," back instead of " "
$wildanimals = ($wildanimals -replace " ", ",")
Join Demo
#store into an array
$wildanimalsarray = $wildanimals -split ","
#join operator takes an array and makes it a string, each element separated by ","
$wildanimalsarray -join ","
Output
========
Tiger,Lion,Elephant,Bear,Fox,Jackal,Hyena
Replace Demo
#replace all instances of Elephant with Zebra
$wildanimals -replace "Elephant","Zebra"
Output
========
Tiger,Lion,Zebra,Bear,Fox,Jackal,Hyena
Conclusion

The case sensitive and insensitive operators are similar in usage except they are sensitive/insensitive to case. Hope this helps you.

Please Share...
Jul 232015
 
Please Share...
Very important:

Please make sure necessary backups are in place before you perform this operation. First test in your dev/test environment and only then use in your production environment.

Ideally a feature will be scoped to a Farm, WebApplication, Site, or Web, but orphaned features won’t be having a scope. The command to list all orphaned features in a SharePoint farm is as follows…

PowerShell command to list all orphaned features…
Get-SPFeature | ? { $_.Scope -eq $null }
Sample output…
PS C:\windows\system32> Get-SPFeature | ? { $_.Scope -eq $null }

DisplayName                    Id                                       CompatibilityLevel   Scope                         
-----------                    --                                       ------------------   -----                         
ReportServerCentralAdmin       5f2e3537-91b5-4341-86ff-90c6a2f99aae     14                                                 
ReportServerStapling           6bcbccc3-ff47-47d3-9468-572bf2ab9657     14                                                 
PowerView                      bf8b58f5-ebae-4a70-9848-622beaaf2043     14                                                 
ReportServerCentralAdmin       5f2e3537-91b5-4341-86ff-90c6a2f99aae     15                                                 
ReportServerStapling           6bcbccc3-ff47-47d3-9468-572bf2ab9657     15                                                 
PowerView                      bf8b58f5-ebae-4a70-9848-622beaaf2043     15
PowerShell command to delete an orphaned feature…
foreach($f in @(Get-SPFeature | ? { $_.DisplayName -eq "ReportServerCentralAdmin" }))
{
    $f.Delete()
}

Why did we need a foreach? Because a feature could be listed twice with different “CompatibilityLevel” values. So in this case “ReportServerCentralAdmin” is listed twice with “CompatibilityLevel” set to 14 and 15. So we delete both via $f.Delete().

Please Share...
Jul 222015
 
Please Share...

Introduction

Get-SPFeature is a command used to list out all the features in a SharePoint farm (scope can be set). You can scope this command to different levels, the levels are…

  • Farm – Only SharePoint farm level features are displayed
  • Web Application – Only web application level features are displayed
  • Site – Only site level features are displayed
  • Web – For sub sites

Examples…

#Display all SharePoint farm features
Get-SPFeature –Limit All
Scoping features…
#Display all SharePoint features scoped to farm
Get-SPFeature -Limit ALL | Where-Object {$_.Scope -eq "FARM"}

#Display all SharePoint features scoped to web application
Get-SPFeature -Limit ALL | Where-Object {$_.Scope -eq "webapplication"}

#Display all SharePoint features scoped to site
Get-SPFeature -Limit ALL | Where-Object {$_.Scope -eq "site"}

#Display all SharePoint features scoped to web
Get-SPFeature -Limit ALL | Where-Object {$_.Scope -eq "web"}
List all features in a Site Collection…

#Displays all SharePoint features for a site collection using Grid view

Get-SPSite http://mysiteurl | Get-SPWeb -Limit ALL |%{ Get-SPFeature -Web $_ } | Out-GridView –Title “All features for this site”

Sample Grid Output…
All Features in a Sharepoint Site Collection

Help…

#For detailed help type in… Get-Help Get-SPFeature –Full

Please Share...
May 012015
 
Please Share...

Here are some sample PowerShell commands to manipulate XML contents in memory and then later dump them to an XML file. I’ve added comments inline to explain a line of PowerShell command.

#Clear output
cls

#Sample XML content
$xml = @'
<?xml version="1.0" encoding="UTF-8"?>
<bookstore>
<book genre="novel" style="hardcover">
<title>The Handmaid's Tale</title>
<author>
<first-name>Margaret</first-name>
<last-name>Atwood</last-name>
</author>
<price>19.95</price>
</book>
<book genre="novel" style="other">
<title>The Poisonwood Bible</title>
<author>
<first-name>Barbara</first-name>
<last-name>Kingsolver</last-name>
</author>
<price>11.99</price>
</book>
<book genre="novel" style="paperback">
<title>The Bean Trees</title>
<author>
<first-name>Barbara</first-name>
<last-name>Kingsolver</last-name>
</author>
<price>5.99</price>
</book>
</bookstore>
'@

# Dump XML to output window
$xml.InnerXml

#Get all attributes named "genre" from above XML
$nodes = $xml.SelectNodes("//@genre")
$nodes.Count 
#Output: 3

#Get first book in the XML
$firstbook = $xml.SelectSingleNode("/bookstore/book[1]")
$firstbook.InnerXml 
#Output: <title>The Handmaid's Tale</title><author><first-name>Margaret</first-name><last-name>Atwood</last-name></author><price>19.95</price>

# Using Select-Xml: Get last book in the XML
$selxml = Select-Xml -Xml $xml -XPath "/bookstore/book[last()]"
$selxml.ToString() 
#Output: <title>The Bean Trees</title><author><first-name>Barbara</first-name><last-name>Kingsolver</last-name></author><price>5.99</price>

# Filter out nodes based on conditions, dump titles of books whose price is greater than 11
$xml.SelectNodes("/bookstore/book[price>11]/title") | Format-Table
#Output: #text 
 # ----- 
 #The Handmaid's Tale 
 #The Poisonwood Bible
 
# Modify XML value of a node, change price
$xml.SelectSingleNode("/bookstore/book[price<11]/price") #Old price
$xml.SelectSingleNode("/bookstore/book[price<11]/price").InnerText = 10 #New Price
$xml.SelectSingleNode("/bookstore/book[price<11]/price") #Print new price
#Output: #text 
 #----- 
 #5.99 
 #10

#Save XML
$xml.Save("$env:userprofile\\desktop\\testxml.xml")
Please Share...
Nov 252014
 
Please Share...

What’s ResourceDigger?

Wrote a utility (long back) for displaying resources from binary files, recently did some modifications as well. We know visual studio does provide a similar functionality but this one’s better with respect to viewing resources. You can view as many resource files as you like (haven’t put a limit). You can drag and drop folders or binaries into the application to get them loaded. Loads up any binary as long LoadLibrary succeeds. Quite useful for a quick view of resources in a binary file, will add editing of resources in the next version of this tool. Hope this helps.

Here is a screenshot of how the tool looks…

ResourceDigger: Application Screenshot

How to use ResourceDigger

Easy to use. Just drag and drop a folder or a bunch of executables. Or…
To load an executable press Ctrl + L or Load Exe toolbar button

ResourceDigger: Load Executable

To load a folder press Ctrl +D, or Scan Folder toolbar button. Select “Load Sub Directories” if you want to recurse into sub-directories.

ResourceDigger: Load a folder of resources

What features are supported in ResourceDigger

Some of the features supported by the application…

  • Viewing animated gifs, normal gifs, pngs, jpegs, bmps, HTML files, manifest files.
  • Display group icons, cursors with detailed description of each of them… See screenshot…
    ResourceDigger: Icon Group Display
  • Friendly display of accelerator table, a good way to know all the shortcuts provided by an application…
    ResourceDigger: Accelerator Resource
  • Friendly display of string table…
    ResourceDigger: String table resource
  • Displays resources in all available languages
    ResourceDigger: Multi Languages Resource
    ResourceDigger: Multi Language Dialog Resource
  • Animated view of AVI file. With a toolbar to control frames in the AVI file.
    ResourceDigger: Version Resource
  • Version display… (there are few issues, I’m working on them)
    image
  • Clear view of registry resources…
    ResourceDigger: Registry Resource
  • Toolbar resource view…
    ResourceDigger: Toolbar Resource
  • Menu resource display…
    ResourceDigger: Menu Resource
  • Hex display of custom resources…
    ResourceDigger: Hex display of unknown resources

Known Issues

  • Hangs up if you give a folder with a humungous list of binaries.
  • This is not multithreaded so just be patient until resources finish loading.

Tips

Press ‘*’ on a particular node to expand all its child nodes.

Download Link (rename from .Jpg to .exe)

Do let me know your suggestions…

Please Share...