【发布时间】:2020-06-09 13:06:19
【问题描述】:
我真的是 Microsoft Graph API 的新手,我使用 powershell 创建了一个脚本来从 Microsoft 365 获取报告,它正在保存在我的驱动器上 (c:\temp\reports.xlsx)。
保存后,我希望将其上传到 SharePoint 在线。在阅读文档时,微软表示要执行以下请求,
PUT /sites/{site-id}/drive/items/{parent-id}:/{filename}:/content
然后我尝试将它应用到我的用例中,这是我的要求:
function RestMethod {
Param (
[parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[String]$Request,
[parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[String]$RequestMethod,
[parameter(Mandatory = $false)]
[ValidateNotNullOrEmpty()]
[String]$Body
)
$Headers = @{
Authorization = "$($global:RequestToken.token_type) $($global:RequestToken.access_token)"
}
$RestResults = $null
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
try {
$RestResults = Invoke-RestMethod -Uri $Request -Headers $Headers -Method $RequestMethod -ContentType "application/json"
} catch {
Write-Host "StatusCode:" $_.Exception.Response.StatusCode.value__
Write-Host "StatusDescription:" $_.Exception.Response.StatusDescription
}
return $RestResults
}
$upLoadRequest = "https://graph.microsoft.com/v1.0/sites/tenant.sharepoint.com/drive/items/Test:/$($File):/content"
$upLoadResults = RestMethod $upLoadRequest 'PUT'
$File 变量包含c:\temp\reports.xlsx 在获取报告时保存我的 excel 文件的目录。我的网址中的Test 是我在我的站点上的Documents 中创建的文件夹。但是在执行请求时,我得到了这个:
StatusCode: 400
StatusDescription: Bad Request
请帮忙
谢谢
【问题讨论】:
标签: powershell sharepoint microsoft-graph-api