Coder Social home page Coder Social logo

andretms / ps-sharepoint-list-graph Goto Github PK

View Code? Open in Web Editor NEW
8.0 1.0 0.0 95 KB

Get SharePoint List Items/fieds via PowerShell using the Microsoft Graph API and MSAL Library

License: MIT License

PowerShell 100.00%
msal sharepoint-online microsoft-graph-api

ps-sharepoint-list-graph's Introduction

Get a SharePoint List via PowerShell using Microsoft Graph API

This sample PowerShell script demonstrate how to get SharePoint List Items/fieds via PowerShell using the Microsoft Graph API via REST.

1. Download Microsoft Authentication Library (MSAL) Library

This sample requires MSAL.NET library for obtaining an Access Token used to query the Microsoft Graph API. Because PowerShell does not have direct integration with nuget, follow the instructions for manual downloading MSAL.NET:

  1. Go to https://www.nuget.org/packages/Microsoft.Identity.Client and select 'Manual Download' to download the MSAL nupkg file.
  2. Rename the file extension to .zip
  3. Extract the zip file to {path}\packages\Microsoft.Identity.Client.1.1.0-preview - where {path} is the folder where your script is saved

2. Register an Application

You need to register an application to be able to access the Microsoft Graph API. In order to do this:

  1. Go to https://apps.dev.microsoft.com/portal/register-app
  2. Add a name for the application and make sure the Guided Setup option is unchecked
  3. Click Create
  4. Now configure the new application to be a Native App by clicking Add Platforms, selecting Native Application and then click Save
  5. Copy the Guid under Application Id to the clipboard

3. Configure your PowerShell Script

  1. Open your PowerShell script and replace the YourAppIdHere with the Application Id for your application you just registered
  2. Now add your Site Relative URL and the List Name by replacing the values of YourSiteRelativeUrlHere and YourListNameHere
##Please replace the three values below
$appId = "YourAppIdHere" 
$SiteRelativeUrl = "YourSiteRelativeUrlHere"
$ListName = "YourListNameHere"

What is my Site Relative URL and my List Name?

Open your SharePoint List in a browser, then check the image below to find out the values for Site Relative URL and your List Name. For the list name, can use both URL encoded with %20 or spaces: Relative Site

4. Run your script

Start a PowerShell session then run the script:

.\PS-SharePoint-List-Graph.ps1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.