Skip to content
DigitalRGS

DigitalRGS

Journey through the Gaming World, Navigate the Social Media Landscape, and Dive into the Tech Realm

Primary Menu
  • Home
  • Gaming World
  • Social Media World
  • Tech World
  • Contact Us
  • Gaming World
    • Freshest Facts
  • Home
  • Latest
  • How to download files from SharePoint with MS Graph API and PowerShell

How to download files from SharePoint with MS Graph API and PowerShell

Renee Straphorn 4 min read
4995

The SharePoint team has released a new way to access the files stored in their site without having to use WebDAV. This is done through Graph API and PowerShell, two richly featured tools that are part of Microsoft Office 365.

The “microsoft graph api get item-id” is a command line tool that allows users to download files from SharePoint. The “Microsoft Graph API” is a Microsoft’s web service that provides access to data in the cloud.

Download SharePoint files from a site to your local device.

I demonstrate how to request all files from SharePoint sites, including child folders, in the lesson below. You may also get them right now by downloading them.

There is no way to accomplish this directly using the Microsoft Graph API URLs in the lesson.

For this, I’ve built two cmdlets in a module that you may utilize.

Accomplish you want to learn how to do it without using a module? Then go to the final paragraph and look at the official Microsoft Graph API documentation links.

Let’s go to work on Optimized. In PowerShell, mga

Using the Microsoft Graph API to get the Authorization token

Powershell is now open!

You may use the following cmdlet to install the module and submodule:

-Scope CurrentUser Install-Module Optimized.Mga.SharePoint

Copy the cmdlet below. Fill in the right values for ApplicationID, ClientSecret, and Tenant.

By invoking the cmdlet, you will generate an Authorization token that will be used by other cmdlets (such as Get-Mga) in the backend.

-ClientSecret ‘XXXX’ -ApplicationID ‘b5954443-ad10-4d1c-8cbc-dc05268a1858’ -Tenant ‘bwit.onmicrosoft.com’ $null = Connect-Mga -ClientSecret ‘XXXX’ -ApplicationID ‘b5954443-ad10-4d1c-8c

You should have gotten a notification saying that you are logged in if everything went fine.


First, let’s look into Get-MgaSharePointFiles.

Get-MgaSharePointFiles looks for the relevant site, as well as any child folders.

There are three parameters, the first of which, ChildFolders, I’ll go over in greater detail below. The other two are simpler to comprehend: TenantName and Site.

TenantName is the name of your tenancy (With or without .onmicrosoft.com). The name of the SharePoint site is Site.

You may obtain all files from a site’s root directory using the following command:

-TenantName’m365x794103.onmicrosoft.com’ -Site ‘XXXX’ produced using Get-MgaSharePointFiles Date: 2021-06-07T10:15:34ZZZZZZZZZZZZZZZZZZZZZZZZ id: 01MIYRG5LAJSJGNXYNRVA2A2XWKCQZ66C6 eTag: “66924C60-0DDF-418D-A06A-F650A19F785E,1” eTag: “66924C60-0DDF-418D-A06A-F650A19F785E,1” eTag: “66924C60-0DDF-418D-A06A- lastModified Date: 2021-06-07T10:15:34ZZZZZZZZZZZZZZZZZZZZZZZZ XXXXXXXXXXXXXXXXXXXX

There is a non-mandatory parameter called ChildFolders. If you don’t provide ChildFolders, the root is utilized instead.

As seen in the picture below, ChildFolders are folders in the root.

How to download files from SharePoint with MS Graph API and PowerShellHow to use the MS Graph API and PowerShell to get files from SharePoint

An array of subfolders may be sent to the ChildFolder option. So, for example, if you wish to search for files in the above-mentioned directory Personal, use the following command:

Get-MgaSharePointFiles -TenantName ‘XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -Site ‘XXXX’ -ChildFolders ‘XXXX’,’Personnel files’,’bas.wijdenes’,’Personal’,’Personal’,’Personal’,’Personal’,’Personal’,’Personal’,’Personal’,’Personal’,’Personal’,’Personal’,’Personal 2021-06-07T14:00:21Z “81017A49-4536-418C-9A71-0A03F46CD0CD,5” eTag: “81017A49-4536-418C-9A71-0A03F46CD0CD,5” id: 01MIYRG5KJPIAYCNSFRRAZU4IKAP2GZUGN lastModified Date: 2021-06-07T14:01:18ZZZZZZZZZZZZZZZZZZZZZZZZ Document.docx is the name of the document.docx file.

All objects in the directory are returned by Get-MgaSharePointFiles. Included in this are the ChildFolders.

This is because you’ll constantly see a list of everything. The drawback is that you will need to filter.

When you use Get-MgaSharePointFiles and save the results in the variable $SPItems, you can use Where-Object to filter through them.

$SPItems = Get-MgaSharePointFiles -TenantName ‘XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Where-Object $_.Name -like “*Document.docx” $SPItem = $SPItems | Where-Object $_.Name -like “*Document.docx”

We now have the proper file in $SPItem and can begin downloading it.


Let’s utilize PowerShell to get a file from SharePoint using Download-MgaSharePointFiles.

Because Download-MgaSharePointFiles is used in conjunction with Get-MgaSharePointFiles, it needs an object from Get-MgaSharePointFiles.

That’s why the fact that we populated the variable $SPItem in the previous chapter comes in handy.

SPItem and OutputFolder are two parameters for Download-MgaSharePointFiles.

The whole object $SPItem is required by SPItem.

OutputFolder is self-explanatory. This is the location where the file will be saved when it has been downloaded.

You may use the following command to download a file from SharePoint:

-SPItem $Item -OutputFolder ‘C:temp’ Download-MgaSharePointFiles

The name of the file will always be the same as it is in SharePoint.

Do you want to get all of the files? The $SPItems may then be used in a foreach loop as follows:

$Item in $SPItems) foreach ‘Download-MgaSharePointFiles -SPItem $Item -OutputFolder ‘C:temp’ ‘Download-MgaSharePointFiles -SPItem $Item -OutputFolder ‘C:temp’ ‘Download-MgaSharePointFiles


The Microsoft Graph API documentation

This lesson makes use of the Microsoft Graph API documentation:

Get a SharePoint site: Microsoft Graph beta | Microsoft Docs | Get a SharePoint site

List a folder’s contents: List a folder’s contents – Microsoft Graph v1.0 | Microsoft Docs

Download the following file: Microsoft Graph v1.0 | Microsoft Docs | Download

Related

Watch This Video-

The “graph explorer” is a PowerShell script that allows users to download files from SharePoint with the MS Graph API. The script requires the .NET Framework 4.0, and was created by Microsoft MVP Adam Driscoll. The script can be downloaded on GitHub here: https://github.com/adamdriscoll/graph-explorer

Related Tags

  • microsoft graph api download attachment
  • microsoft graph api drives
  • microsoft graph api download sharepoint file c#
  • upload file to sharepoint document library using graph api
  • microsoft graph api onedrive example c#

About The Author

Renee Straphorn

See author's posts

Continue Reading

Previous: How to Take Screenshot In Motorola Moto G51 5G
Next: Dell Launches ‘Concept Luna’ as a step towards Sustainable PC design

Related Stories

Worldcoin: Unique Features that Make this Crypto Project Stand Out Image1
4 min read

Worldcoin: Unique Features that Make this Crypto Project Stand Out

Maggie Hopworth 24
BNB’s Journey From A Bold Ico To The Fifth-Largest Crypto In A Sea Of 17,000+ Free Silver cryptocurrency coins arranged on a wooden surface spelling 'crypto'. Stock Photo
5 min read

BNB’s Journey From A Bold Ico To The Fifth-Largest Crypto In A Sea Of 17,000+

Renee Straphorn 47
Has Your Email Been Hacked? Here’s How to Check and What to Do
5 min read

Has Your Email Been Hacked? Here’s How to Check and What to Do

Renee Straphorn 68
The Betting Ladder: Climbing from Low Stakes Fun to High Roller Territory Image2
5 min read

The Betting Ladder: Climbing from Low Stakes Fun to High Roller Territory

Renee Straphorn 71
Ukrainian Brides: Myths & Facts Image2
4 min read

Ukrainian Brides: Myths & Facts

Renee Straphorn 80
What Are the Advantages of Playing in Mobile Online Casinos?
5 min read

What Are the Advantages of Playing in Mobile Online Casinos?

Renee Straphorn 85

What’s Hot

What are the key features of Ometria? ometria crm 40m 75m butchertechcrunch

What are the key features of Ometria?

March 27, 2023
Moss is a spend management app that helps businesses keep track of their spending moss 75m series tiger 500mdillettechcrunch

Moss is a spend management app that helps businesses keep track of their spending

March 27, 2023
Bibit is a robo-advisor app for Indonesian investors bibit 30m sequoia capital 45mshutechcrunch

Bibit is a robo-advisor app for Indonesian investors

March 27, 2023
What are the key features of Ometria? ometria crm 40m 75m butchertechcrunch

What are the key features of Ometria?

March 27, 2023
Why the Alexa Turing Test is Important the alexa turing test fastcompany

Why the Alexa Turing Test is Important

December 20, 2022

3981 Solmonel Avenue
Melos, SC 10486

  • Privacy Policy
  • Terms & Conditions
  • About Us
  • Freshest Facts
© 2022 Digitalrgs.org
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept”, you consent to the use of ALL the cookies.
Do not sell my personal information.
Cookie SettingsAccept
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Functional
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytics
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
Others
Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.
SAVE & ACCEPT