最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

office365 - Creating folders in OneDrive via PowerShell - Stack Overflow

programmeradmin4浏览0评论

I am unable to create files/folders in my OneDrive, I got this message: Resolve-PnPFolder : The remote server returned an error: (403) Forbidden

Microsoft changed how to connect via PnP and now no one can connect with a user. I do have an application and I am trying to connect with ClientID and Secret when connecting I am getting this warning:

WARNING: Connecting with Client Secret uses legacy authentication and provides limited functionality. We can for instance not execute requests towards the Microsoft Graph, which limits cmdlets related to Microsoft Teams, Microsoft Planner, Microsoft Flow and Microsoft 365 Groups. You can hide this warning by using Connect-PnPOnline [your parameters] -WarningAction Ignore

I added almost everything in App permissions and still got this message, what could be the reason?

$OneDriveSiteURL = ";

Connect-PnPOnline -Url $OneDriveSiteURL -ClientId "3ed262a0-f02e-48f4-9ede-ef90c76aXXXX" -ClientSecret "dAs8Q~XXXXkdmF4bF3UI1Hke2yxtTgXXXX"

I can tell that we used a Nuget that someone prepared and it worked as expected with the same App registration, we must use PowerShell instead of this Nuget (there is a reason for that...)

I used this and it's working but it creates a folder in SPO and not in OD why?

OneDrive FB create Folder with Microsoft Graph API Powershell

$clientId = "XXXXXXXXXXXXXX"
$tenantId = "XXXXXX.onmicrosoft"
$clientSecret = 'XXXXXXXXXXXX'


$uri = "/$tenantId/oauth2/v2.0/token"


$body = @{
    client_id     = $clientId
    scope         = "/.default"
    client_secret = $clientSecret
    grant_type    = "client_credentials"
}

$tokenRequest = Invoke-WebRequest -Method Post -Uri $uri -ContentType "application/x-www-form-urlencoded" -Body $body -UseBasicParsing
$token = ($tokenRequest.Content | ConvertFrom-Json).access_token
Write-Host $token


$uri = ".0/<ID XXXXXXX>/drive/root/children"
$method = 'POST'
$head= @{Authorization = "Bearer $token"} 
$postPara= @{
name= "NewFolder"
folder= {}
} | ConvertTo-Json


$antwort = Invoke-RestMethod -Headers $head -Uri $uri -Method $method -Body $postPara -ContentType "application/json"
Write-Host $antwort
发布评论

评论列表(0)

  1. 暂无评论