1

I am trying to create a list view DYNAMICALLY using PowerShell. CAML query is

$viewQuery = "<Where><Eq><FieldRef Name='PPL' /><value Type='User'>[Me]</value></Eq></Where>"

This updates the view with PPL and value as "[Me]". but the list is not showing any data. But when I open the updated view and just save it, the list is showing current user data.

Why powershell caml query is not take [Me] as the value?

Any Ideas?

Thanks Venkat

1 Answer 1

2

Please run the below PowerShell script as an admin on SharePoint Online Management Shell:

#Config Variables
$SiteURL = "https://{domain}.sharepoint.com/sites/{sitename}"
$ListName= "{listname}"
$ViewName= "{Test View}"
$ViewFields = @("Title","Dimension","Format","PPL","ProceedDate")

$Query = "<Where><Eq><FieldRef Name='PPL'/><Value Type='Integer'><UserID/></Value></Eq></Where>"
 
#Get Credentials to connect
$Cred = Get-Credential
 
Try {
    #Connect to PnP Online
    Connect-PnPOnline -Url $SiteURL -Credentials $Cred
 
    #sharepoint online pnp powershell create view
    Add-PnPView -List $ListName -Title $ViewName -ViewType Html -Fields $ViewFields -Query $Query -ErrorAction Stop
    Write-host "View '$ViewName' Created Successfully!" -f Green
}
catch {
    write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
}

Here is my test:

This is my list:

enter image description here

Run the PowerShell script:

enter image description here

Create new view:

enter image description here

enter image description here

1
  • Elaborate answer. This worked. Thank you. Commented Dec 8, 2021 at 14:16

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.