Use the function declared in this script to retrieve search results from SharePoint search via a dynamic web service proxy call to the SharePoint Search Web Service (search.asmx). The function utilizes PowerShell's New-WebServiceProxy cmdlet to dynamically create a web service client, and creates appropriate XML to submit the Search Query request.

PowerShell
Edit|Remove
function Query-SPSearch { 
    param( 
        [Parameter(Mandatory=$true)] 
        [String] 
        $WebApplicationPath, 
        [Parameter(Mandatory=$true)] 
        [String] 
        $KeywordQuery, 
        [Parameter()] 
        [Int32] 
        $Count = 10 
    ) 
$QueryXml = @" 
<QueryPacket xmlns="urn:Microsoft.Search.Query" > 
    <Query> 
        <Context> 
            <QueryText type="STRING">$KeywordQuery</QueryText> 
        </Context> 
        <Range> 
            <Count>$Count</Count> 
        </Range> 
        <IncludeSpecialTermResults>false</IncludeSpecialTermResults> 
        <PreQuerySuggestions>false</PreQuerySuggestions> 
        <HighlightQuerySuggestions>false</HighlightQuerySuggestions> 
        <IncludeRelevantResults>true</IncludeRelevantResults> 
        <IncludeHighConfidenceResults>false</IncludeHighConfidenceResults> 
    </Query> 
</QueryPacket> 
"@ 
    $ServicePath = "/_vti_bin/search.asmx" 
 
    $SearchWS = New-WebServiceProxy -Uri ($WebApplicationPath + $ServicePath-UseDefaultCredential 
    $Results = $SearchWS.QueryEx( $QueryXml ) 
    # we excluded all other result sets, but just in case get the one we want: 
    $Results.Tables["RelevantResults"] 
}