Pages

Sunday 11 November 2012

How to get crawled properties for a document using Powershell in SharePoint 2010


(This is an exact copy from this site: I have created this post for my Personal Reference)


In order to get the crawled properties for a document copy the powershell command, this information can be used to create Managed Properties for search.



Function Get-CrawledPropertyNames([string]$DocURL){  
$DocURL = $DocURL.Replace("%20"," "$webfound = $false 
$weburl = $DocURL 
 
while ($webfound -eq $false) { 
    if ($weburl.Contains("/")){ 
    $weburl = $weburl.Substring(0,$weburl.LastIndexOf("/")) 
    $web = get-spweb -identity $weburl -ea 0 
    if ($web -ne $null){ 
        $webfound = $true 
    } 
    }else{ 
    Write-Host -ForegroundColor Red "The Web could not be found" 
    return -1 
    } 
     
} 
$web.GetFile($DocURL).item.xml.Replace("' ""' `n").Replace("`" ", "`" `n") 
} 


#To use enter the url of a file within a doucment library 
Get-CrawledPropertyNames "http://sites/doc/file.pdf" 
 
The output: 




No comments:

Post a Comment