I am working on a powershell script to start the workflow on items in a list,

$url = “https://xxxxx.sharepoint.com/sites/xxxxxxxxxxxx” 
$username = "username" 
$password = Read-Host -Prompt "Enter password" -AsSecureString  

$clientContext = New-Object Microsoft.SharePoint.Client.ClientContext($url);

$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $password)  
$clientContext.Credentials = $credentials 

$list = $clientContext.Web.Lists.GetByTitle("contracten");
$query = New-Object Microsoft.SharePoint.Client.CamlQuery;
$query.ViewXml = "<OrderBy><FieldRef Name='Actie_x0020_datum'  Ascending='False' /></OrderBy>"
$listItems = $list.GetItems($query);

$tasks =@();
foreach ($listItem in $listItems)
     Write-Host $ListItem.Id


In the for loop, i let it print the Id's of the list item so I can see the order of the items. Whatever I try, it always returns the items in the same order, and nog ordering them by the field that I am trying to sort on.

Can anyone see if there is something that I do wrong? I'm struggling with this for days now.

1 Answer 1


The ViewXml you have does not conform to the XML schema it expects. It should have a <View> tag and a <Query> tag:

$query.ViewXml = "<View><Query><OrderBy><FieldRef Name='Actie_x0020_datum' Ascending='False' /></OrderBy></View></Query>"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.