Forum Discussion
María José Pedreira
Jul 05, 2017Brass Contributor
Powershell. Retrieve filtered information from a list using WebClient class
Hello,
I need obtain information from a list using next call:
$url="http://myhost/_api/web/lists/GetByTitle('mylist')/items?$select=Title,CurrentYear&$filter=CurrentYear%20gt%202019" $webclient = new-object System.Net.WebClient $webclient.UseDefaultCredentials = $true $webpage = $webclient.DownloadString($url) $webpage
If I type the rest url in a browser I obtain my results filtered. It works fine.
But the same url in the previous code retrieves all the items. When I type $webpage, the results seem to ignore the url text after the ? symbol.
Thank you!
- I would recommend to use CSOM....it's not an option for you?
- María José PedreiraBrass Contributor
jcgonzalezmartin and Pieter Veenstra, sorry for my delay... holiday....
The problem was concatenating strings. Using this way runs:
$url = “http://myhost/_api/web/lists/GetByTitle(%27mylist%27)/items?" + "$" + "select=Title,IDPeticio&" + "$" + "filter=IDPeticio%20gt%205080"