Powershell. Retrieve filtered information from a list using WebClient class

Highlighted
Contributor

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!

 

3 Replies
I would recommend to use CSOM....it's not an option for you?
Highlighted

@Juan Carlos González Martín 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"