Add-Type -AssemblyName System.Web
$sServerPath = "http://Siteurl"
$sQueryOptions = "selectproperties='ManagedPropertyName'&clienttype='ContentSearchRegular'&QueryTemplatePropertiesUrl='spfile://webroot/queryparametertemplate.xml'"
$sUserName = "user name"
$sPassword ="password"
$sDomain="domain name"
$WebRMethod=[Microsoft.PowerShell.Commands.WebRequestMethod\]::Get
function Get-SPSearchResults {
param ($keyword,$sUserName,$sPassword, $sDomain, $WebRMethod)
try
{
$spCredentials = New-Object System.Net.NetworkCredential($sUserName,$sPassword,$sDomain)
$enckeyword = [System.Web.HttpUtility]::UrlEncode("'$keyword'")
$url = $sServerPath+"/_api/search/query?querytext=$enckeyword"+"&$sQueryOptions"
$spWebRequest = [System.Net.WebRequest]::Create($url)
$spWebRequest.Credentials = $spCredentials
$spWebRequest.Accept = "application/json;odata=verbose"
$spWebRequest.Method=$WebRMethod
$spWebResponse = $spWebRequest.GetResponse()
$spRequestStream = $spWebResponse.GetResponseStream()
$spReadStream = New-Object System.IO.StreamReader
$spRequestStream $spData=$spReadStream.ReadToEnd()
$results = $spData | ConvertFrom-Json
$results = $results.d.query.PrimaryQueryResult.RelevantResults.Table.Rows.results
for($i=0; $i -le $results.length-1; $i++) {
$row = $results\[$i\]
for ($j=0; $j -le $row.Cells.results.length-1; $j++) {
if ($row.Cells.results\[$j\].Key -eq 'Title') {
Write-Host $row.Cells.results\[$j\].Value -ForegroundColor Green
}
}
}
}
catch
{
Write-Host $\_.Exception.Message -ForegroundColor Red
}
}
try {
Get-SPSearchResults -keyword "ca" -sUserName $sUserName -sPassword $sPassword -sDomain $sDomain -WebRMethod $WebRMethod
}
catch {
Write-Host "Problem in running the REST API. Failed with error : " + $_.Exception.Message -ForegroundColor Red
}
Read Next
Package and Deploy SharePoint Framework WebPart
Simple Angular WebPart using SharePoint Framework Preview
Tags
.NET
AI
ALB
API
ARM
ASPM
AWS
Actions
Amazon Bedrock
Angular
Ansible
Anti-Pattern
Architecture
Automation
Azure
Azure AD
Azure CLI
Azure Container Apps
BDC
Bash
Bitbucket
Bot
CDN
CI/CD
CLI for Microsoft 365
CSOM
Citrix
Claude AI
Cloud Computing
CloudFront
CloudWatch
Cloudflare Workers
CodeWhisperer
Community
Computer Vision API
Copilot
Data Extraction
DeepSeek
DefectDojo
DevOps
DevSecOps
Distributed Systems
Docker
Docker Scout
DynamoDB
EKS
ElastiCache
Event Driven
EventBridge
External Secrets Operator
Faith
Flask
GCP
Generative AI
GitHub
GitLab
GitLeaks
GitOps
Google Analytics
Governance
Graph API
Groups
HIBP API
Hashicorp
IAM
IaC
Identity
Incident-Response
InfoPath
Integration
Istio
JavaScript
Jenkins
Jinja2
Kafka
Kiali
Knowledge Base
Kubernetes
LLM
LUIS
Lambda
Lambda@Edge
LangChain
Linode
Linux
Lotus Notes
MCP
MCP server
Machine Learning
Manage Secrets
Media Processing
Microservices
Microsoft 365
Microsoft Power Platform
Migration
Milvus
Model Context Protocol
NJSScan
Nintex
OIDC
Office Store
Ollama
OpenAI
Performance Optimization
Permissions
Pinecone
PnP
Pod
Postman
Power Apps
Power Automate
PowerShell
Python
RAG
REST
Redis
Roles
S3
SNS
SPFx
SQL Server
SRE
SSL
SSRS
Security
Semantic Search
Semgrep
Serverless
Service Mesh
ServiceNow
SharePoint
Slack
Software Engineering
TFS
Teams
Terraform
VM
Vault
Vector Database
Vulnerability
Windows
Windows Server
YAML
Yammer
jQuery
tfsec