Skip to content
EuroGamersOnline

EuroGamersOnline

Always in control

Primary Menu
  • Home
  • Console Gaming
  • PC Gaming
  • Gadgets
  • Contact Us
  • Home
  • Latest
  • How to upload files to SharePoint with MS Graph API and PowerShell

How to upload files to SharePoint with MS Graph API and PowerShell

13

Microsoft Graph API and PowerShell provide a way to upload files to SharePoint using Office 365, providing an alternative means of uploading large amounts of data while still utilizing the power of online file storage.

The “upload file to sharepoint using graph api c#” is a tutorial that will show you how to upload files to SharePoint with the MS Graph API and PowerShell.

Using PowerShell to upload files to OneDrive or SharePoint using the Microsoft Graph API

I’ll show you how to upload files to SharePoint sites, including child folders, in the lesson below.

There is no way to accomplish this directly using the Microsoft Graph API URLs in the lesson. For your convenience, I’ve included a cmdlet in a module.

Achieve you want to know how you can do this without 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.


We simply need one cmdlet this time: To upload files, use Upload-MgaSharePointFiles.

Upload files to SharePoint sites and OneDrives using Upload-MgaSharePointFiles. The cmdlet is included as part of the module. It takes the following value as a parameter:

  • TenantName
  • Site
  • ItemPath / Item
  • ChildFolders

TenantName and Site are self-explanatory. The TenantName is the address ‘*.onmicrosoft.com’. The Site field specifies the URL of the site to which you wish to upload a file.

The Item or ItemPath argument differs somewhat. The path string to the item you wish to upload to SharePoint is sent to ItemPath.

You may pick ‘Copy as path’ when you Shift + Right click a file, as seen in the image below. “C:tempblatemp.txt” will be the path for the copy.

How to upload files to SharePoint with MS Graph API and PowerShell How to use the MS Graph API and PowerShell to upload files to SharePoint

-ItemPath “C:tempblatemp.txt” -TenantName “m365x794103.onmicrosoft.com” -Site “XXXX” Upload-MgaSharePointFiles -ItemPath “C:tempblatemp.txt” -TenantName “m365x794103.onmicrosoft.com”

The argument Item takes an item from the [System.IO.FileSystemInfo] object. That is, before you start Upload-MgaSharePointFiles, you must first run Get-Item -Path C:tempblatemp.txt.

-Item Upload-MgaSharePointFiles (Get-Item “C:tempblatemp.txt”) -Site ‘XXXX’ -TenantName’m365x794103.onmicrosoft.com’ createdBy: @application=; user=; createdBy: @application=; user=; createdBy: @application=; user=; Date: 2021-12-15T17:03:27ZZZZZZZZZZZZZZZZZZZZZZZ id: 01MIYRG5I55BYRTHLDVZEJQTJWXXQDVKWP eTag: “1971E81D-639D-48AE-984D-36BDE03AAACF,7” eTag: “1971E81D-639D-48AE-984D-36BDE03AAACF,7” eTag: “1971E81D-639D-48AE-984D-36BDE03A lastModifiedBy: @application=; lastModifiedBy: @application=; lastModifiedBy: @application=; lastModifiedBy: @application=; last Date: 2021-12-15T18:27:32ZZZZZZZZZZZZZZZZZZZZZZZ blatemp.txt is a text file with the name blatemp.txt.

It all depends on how Upload-MgaSharePointFiles will be used. Do you wish to upload things in bulk? I’d recommend starting with Get-Item / Get-ChildItem and then using a foreach loop.

Get-ChildItem -Path’C:temp’foreach ($item in $Items) $Items = Get-ChildItem -Path’C:temp’foreach ($item in $Items) $Items = Get-ChildItem – -Item Upload-MgaSharePointFiles $item -Site ‘XXXX’ -TenantName ‘XXXX’

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

An array of subfolders may be sent to the ChildFolder option. You may use the following command to upload a file to a subfolder:

-Item Upload-MgaSharePointFiles (Get-Item “C:tempblatemp.txt”) -ChildFolders ‘XXXX’,’Personnel files’,’bas.wijdenes’,’Personal’ -TenantName ‘XXXX’,’Personal’,’Personal’,’Personal’,’Personal’,’Personal’,’Personal’,’Personal’,’Personal’,’Personal’,’Personal’ @application=; user=; createdBy: @application=; user=; createdBy: @application=; user=; createdB Date: 2021-12-15T17:03:27ZZZZZZZZZZZZZZZZZZZZZZZZZZZ “1971E81D-639D-48AE-984D-36BDE03AAACF,7” is an eTag. 01MIYRG5I55BYRTHLDVZEJQTJWXXQDVKWP id: 01MIYRG5I55BYRTHLDVZEJQTJWXXQDVKWP id: 01MIYRG5I55 @application=; user=; lastModifiedBy: 2021-12-15T18:27:32Z lastModifiedDateTime blatemp.txt is a text file with the name blatemp.txt.

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

How to upload files to SharePoint with MS Graph API and PowerShellHow to use the MS Graph API and PowerShell to upload files to SharePoint


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

Microsoft Docs | Resumable file upload: Resumable file upload – Microsoft Graph v1.0

Related

The “powershell post file to api” is a PowerShell command that can be used to upload files to SharePoint using the MS Graph API.

Related Tags

  • upload folder to sharepoint online powershell ms graph
  • upload file in powershell
  • powershell upload file to box
  • invoke-webrequest upload binary file
  • box com powershell

Continue Reading

Previous: Best 8 Ways To Download Reels From Instagram For Free
Next: How to Delete Badoo Account Permanently? [Updated December 2021]

Trending Now

What are Some of the Challenges Associated with Look Wellsaid? look wellsaid vocalid aihao mit technologyreview 1

What are Some of the Challenges Associated with Look Wellsaid?

January 19, 2023
How Kustomer’s Software Could Benefit Facebook sources facebook kustomeryun cheereuters 2

How Kustomer’s Software Could Benefit Facebook

January 19, 2023
What Found Offers Self-Employed Business Owners 3

What Found Offers Self-Employed Business Owners

January 19, 2023
The Features of the New Studio Display Powered by the iPhone Chip studio hey siriwelch theverge a13 bionic 4

The Features of the New Studio Display Powered by the iPhone Chip

January 19, 2023
What Drove Dropbox’s Success in Q1? dropbox q1 yoy 15.83m 14.59m yoycondonzdnet 5

What Drove Dropbox’s Success in Q1?

January 19, 2023

Related Stories

Here are some of the things you should consider when choosing a gambling website

Here are some of the things you should consider when choosing a gambling website

28
How to Repair: Steam Disk Read Error on Windows PC

How to Repair: Steam Disk Read Error on Windows PC

30
What is a WEBP file & how to open it?

What is a WEBP file & how to open it?

21
Your mouse is moving erratically? Top 5 solutions to fix it

Your mouse is moving erratically? Top 5 solutions to fix it

20
How to fix the Windows 11 error code 0x800f0830

How to fix the Windows 11 error code 0x800f0830

22
[4 Ways] How To Recover Blocked Messages On Android/Samsung

[4 Ways] How To Recover Blocked Messages On Android/Samsung

40

Trending News

How Amazon Kindle Makes it Easier to Load eBooks you Didn’t Buy From Amazon 1

How Amazon Kindle Makes it Easier to Load eBooks you Didn’t Buy From Amazon

January 19, 2023
How Citibank Learned its Lesson 2

How Citibank Learned its Lesson

January 19, 2023
Why EA is Sought After by Amazon, Disney, and Apple 3

Why EA is Sought After by Amazon, Disney, and Apple

January 19, 2023
The Rise of Tech Start-Ups in South-East Asia 4

The Rise of Tech Start-Ups in South-East Asia

January 19, 2023
How Anitian Helps Businesses Secure Their Data 5

How Anitian Helps Businesses Secure Their Data

January 19, 2023
All rights reserved to EuroGamerOnline