PowerShell Graph SDK – SharePoint List Operations

 

We have used CSOM, PNP, REST/Graph API in the past to do SharePoint List operations.

Now we will explore PowerShell Graph SDK to do same kind of operations.

It is bit tricky, but I will share the problems faced during its implementation.

 

Why have We used it instead of PNP?

We have written a solution where some cmdlets are available in Graph SDK, some are in Intune module and others are in PNP.

So, we have combined it all together to just use Graph SDK and single authentication mechanism.

Connect to graph

Connect-MgGraph -ClientId $ClientID -CertificateThumbprint $ThumbPrint -TenantId $TenantName

If you want to connect to Beta Endpoint, then use below command:

Select-MgProfile -Name “beta”

 

Lesson Number 1:

When we were using this module, we found that we were only able to get items from one list out of dozens of others in the same Site.

On further checking, we have found that all lists have item level permission set and permission Site.Read.All is not enough, we need to provide Site.FullControl.All


 

Lesson Number 2:

To get List items

$ListItems = Get-MgSiteListItem -SiteId $siteid -ListId $listid -ExpandProperty ‘fields’ -filter “fields/Status eq ‘InProgress'”

Fetch the field values – $listItem.Fields.AdditionalProperties is required.

Example to fetch Status field Value.


 

Lesson Number 3:

When we were writing field values using Update-MgSiteListItem, we were getting (Field not recognized

Error) same as others reported on internet.

What resolved it for us is upgrade the Graph SDK to newer version and utilizing below Syntax.

Example to update Status Field:

Update-MgSiteListItem -SiteId $siteid -ListId $listid -ListItemId $id -Fields @{“Status” = “DeviceNotFound”}

I hope these three above lessons will save you a lot of time which we wasted figuring out how to work with SharePoint Online list items using graph SDK.

 

Thanks for reading …

Tech Wizard

https://techwizard.cloud

https://syscloudpro.com/

PowerShell Fast Track

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s