I'm trying to search SharePoint using PowerShell and REST web services…
PS C:\> Invoke-WebRequest http://spserver/sites/demo3/_api/search/query?querytext='sharepoint' -UseDefaultCredentials
I keep getting:
Invoke-WebRequest : The remote server returned an error: (400) Bad Request.
I spent the last hour doing web searches for "400" errors and Invoke-WebRequest and SharePoint and search etc.
Talk about the forest and the trees… The problem was with basic PowerShell strings in parameters. The single quotes got me! Quotes around strings should be required on parameters, but PowerShell lets you be lazy and leave them off… most of the time. Here's the correct solution:
PS C:\> Invoke-WebRequest "http://spserver/sites/demo3/_api/search/query?querytext='sharepoint'" -UseDefaultCredentials
The only change was the addition of double quotes. Everything now works as expected! A full hour wasted climbing the wrong trees.
In the forest of ASCII, watch out for the quote trees…
.
No comments:
Post a Comment
Note to spammers...
Spammers, don't waste your time... all posts are moderated. If your comment includes unrelated links, is advertising, or just pure spam, it will never be seen.