PowerShell – Access Windows Search

February 10, 2015

Windows has a Search feature that integrates in the OS and as well in Outlook.

Using the Control Panel you access the settings, which folders to index and which folders or Email folders.

image

image

To access the Search database you can use the “Search.CollatorDSO” Provider.

CLS

# GENERAL_COLUMNS
#$GENERAL_COLUMNS = "System.Kind"
$GENERAL_COLUMNS = "System.ItemPathDisplay"
#$GENERAL_COLUMNS = "System.ItemFolderPathDisplay"
#$GENERAL_COLUMNS = "System.Size"
#$GENERAL_COLUMNS = "System.DateCreated"
#$GENERAL_COLUMNS = "System.Author"
#$GENERAL_COLUMNS = "System.Keywords"

# DOCUMENT_COLUMNS
#$GENERAL_COLUMNS = "System.Image.HorizontalSize"
#$GENERAL_COLUMNS = "System.Image.VerticalSize"
#$GENERAL_COLUMNS = "System.Image.BitDepth"
#$GENERAL_COLUMNS = "System.Image.Compression"
#$GENERAL_COLUMNS = "System.Photo.CameraModel"
#$GENERAL_COLUMNS = "System.Photo.DateTaken"
#$GENERAL_COLUMNS = "System.Photo.Flash"

# MUSIC_COLUMNS
#$GENERAL_COLUMNS = "System.Music.Artist"
#$GENERAL_COLUMNS = "System.Music.Genre"
#$GENERAL_COLUMNS = "System.Music.TrackNumber"
#$GENERAL_COLUMNS = "System.Audio.Compression"
#$GENERAL_COLUMNS = "System.Audio.SampleRate"
#$GENERAL_COLUMNS = "System.DRM.IsProtected"
#$GENERAL_COLUMNS = "System.Music.AlbumTitle"
#$GENERAL_COLUMNS = "System.Rating"
#$GENERAL_COLUMNS = "System.Audio.EncodingBitrate"

# VIDEO_COLUMNS
#$VIDEO_COLUMNS = "System.RecordedTV.ChannelNumber"
#$VIDEO_COLUMNS = "System.RecordedTV.EpisodeName"
#$VIDEO_COLUMNS = "System.RecordedTV.NetworkAffiliation"
#$VIDEO_COLUMNS = "System.RecordedTV.RecordingTime"
#$VIDEO_COLUMNS = "System.Video.Compression"
#$VIDEO_COLUMNS = "System.Video.EncodingBitrate"
#$VIDEO_COLUMNS = "System.Video.FrameHeight"
#$VIDEO_COLUMNS = "System.Video.FrameWidth"    
  
$keyword1 = "PowerShell"  
$keyword2 = "au3"  
$extension = ".PDF"
$folder = "C:\"  


$objConnection = New-Object -com ADODB.Connection  
$objRecordSet = New-Object -com ADODB.Recordset

$objConnection.Open("Provider=Search.CollatorDSO;Extended Properties='Application=Windows';")  
$objRecordSet.Open("SELECT $GENERAL_COLUMNS FROM SYSTEMINDEX WHERE System.FileExtension = '$extension' `
                    AND (Contains(Contents,'$keyword1') OR Contains(Contents, '$keyword2')) `
                    AND System.ItemPathDisplay LIKE '$folder\%'", $objConnection)  

if ($objRecordSet.EOF -eq $false) {$objRecordSet.MoveFirst() }  
  
while ($objRecordset.EOF -ne $true) {  
  $objRecordset.Fields.Item("System.ItemPathDisplay").Value  
  $objRecordset.MoveNext()  
 }


rv folder, extension, keyword1, keyword2

As you can see there are many columns you can search. Or using some Queries you can run this on your indexed mails

image

The bonus you get it that you can use this technology to do Remote Search over your network on a remote server or PC.

Enjoy !

Advertisements

SharePoint – Search Slow opening documents

January 25, 2015

At the moment I have an problem in a certain side collection. Where the search result page appears quickly.

But when clicking any of the results to open a document, it takes more then 5 seconds Sad smile

So the next step is to see if a full Crawl of the search database, does not solve the problem.

Solution :

Go to Central Adminstration

clip_image002

Next go to Manage service applications –> Search Service Application

image

Go to Local SharePoint Sites and select Full Crawl from the dropdown menu.

There are more interesting options in the side menu.

Or you can use PowerShell to do the same.

CLS

if((Get-PSSnapin | Where {$_.Name -eq "Microsoft.SharePoint.PowerShell"}) -eq $null)
{
    Add-PSSnapin Microsoft.SharePoint.PowerShell;
}
        
# Get current Status
Get-SPEnterpriseSearchCrawlContentSource -SearchApplication "Search Service Application" | select Name, CrawlStatus



Get-SPEnterpriseSearchCrawlContentSource -SearchApplication "Search Service Application" | ForEach-Object {
    if ($_.CrawlStatus -ne "Idle")
    {
        Write-Host "Stopping currently running crawl for content source $($_.Name)..."
    #    $_.StopCrawl()
        
        do { Start-Sleep -Seconds 1 }
        while ($_.CrawlStatus -ne "Idle")
    }
    
    Write-Host "Starting full crawl for content source $($_.Name)..."
    # $_.StartFullCrawl()
}

After starting the Full Crawl everything was working again Smile


SharePoint – Monitor the Search service

January 14, 2015

Sometime when you hit a performance issue on your SharePoint Server.

This can be caused by the Search Service being to aggressive or taking too long to crawl the data.

Well using Powershell we can list the status and details of the Search Services.

CLS

if((Get-PSSnapin | Where {$_.Name -eq "Microsoft.SharePoint.PowerShell"}) -eq $null)
{
    Add-PSSnapin Microsoft.SharePoint.PowerShell;
}
        
Write-Host "Search Service Status ..."
Get-SPSearchService

Write-Host "Search Crawl Service details ..."
$crawlSource = Get-SPEnterpriseSearchCrawlContentSource `
                -SearchApplication (Get-SPEnterpriseSearchServiceApplication)

$crawlSource

 

Output will look like this.

image

Where you can see how long it took the last time and whether the service is still active or Idle.

Sometime the server is overloaded if the Crawl schedules take too long and are overlapping each other.

So this can give you a starting point for debugging Winking smile