通过PowerShell脚本使用图形api将文件上载到sharepoint

通过PowerShell脚本使用图形api将文件上载到sharepoint,powershell,file-upload,microsoft-graph-api,shared-libraries,azure-ad-graph-api,Powershell,File Upload,Microsoft Graph Api,Shared Libraries,Azure Ad Graph Api,我无法找到确切的一步一步的程序。请让我知道不同的可能性。我编写了一个脚本,在Powershell脚本中创建一个临时令牌,以连接到graph api,因此无法进一步编写代码。有人可以帮我吗。您可以通过调用以下API将文件上载到SharePoint: Put /v1.0/sites/{tenant}.sharepoint.com/drive/root:/Test/reports.xslt:/content 这是一个简单的例子: $access_token = "--access toke

我无法找到确切的一步一步的程序。请让我知道不同的可能性。我编写了一个脚本,在Powershell脚本中创建一个临时令牌,以连接到graph api,因此无法进一步编写代码。有人可以帮我吗。

您可以通过调用以下API将文件上载到SharePoint:

Put /v1.0/sites/{tenant}.sharepoint.com/drive/root:/Test/reports.xslt:/content
这是一个简单的例子:

$access_token = "--access token goes here--"
$path = "--path to local file, e.g. c:\data\report.xlsx--"

$url = "https://graph.microsoft.com/v1.0/sites/{tenant}.sharepoint.com/drive/root:/{folder}/{filename}:/content"
$headers = @{'Authorization' = "Bearer $access_token" }
Invoke-RestMethod -Uri $url -Headers $headers -Method Put -InFile $path -ContentType 'multipart/form-data'
还有一个类似的问题,希望能对你有所帮助