gpt4 book ai didi

powershell - 与外部用户共享的Onedrive API列表文件

转载 作者:行者123 更新时间:2023-12-02 23:58:32 25 4
gpt4 key购买 nike

我正在使用PowerShell和OneDrive API来完成此任务。我可以获取所有文件夹/文件/ etc,但是我很难找到可以列出某个文件已共享给所有用户的位置。我的范围已经包含wl.skydrive_contacts,并且我已经使用API​​列出了所有文件夹/文件。谁能给我一些见识?

最佳答案

您可以使用OneDrive Rest API列出所有共享项目。

在此之前,您需要注册一个应用程序才能根据https://dev.onedrive.com/app-registration.htm正确访问OneDrive。

然后,您可以使用下面的代码。

$ClientId = "<Your application client id>" # your application clientid 
$SecrectKey = "<Your application key>" # the secrect key for your application
$RedirectURI = "<Your web app redirect url>" # the re-direct url of your application

Function List-SharedItem
{
[CmdletBinding()]
Param
(
[Parameter(Mandatory=$true)][String]$ClientId,
[Parameter(Mandatory=$true)][String]$SecrectKey,
[Parameter(Mandatory=$true)][String]$RedirectURI
)

# import the utils module
Import-Module ".\OneDriveAuthentication.psm1"

# get token
$Token = New-AccessTokenAndRefreshToken -ClientId $ClientId -RedirectURI $RedirectURI -SecrectKey $SecrectKey

# you can store the token somewhere for the later usage, however the token will expired
# if the token is expired, please call Update-AccessTokenAndRefreshToken to update token
# e.g.
# $RefreshedToken = Update-AccessTokenAndRefreshToken -ClientId $ClientId -RedirectURI $RedirectURI -RefreshToken $Token.RefreshToken -SecrectKey $SecrectKey

# construct authentication header
$Header = Get-AuthenticateHeader -AccessToken $Token.AccessToken

# api root
$ApiRootUrl = "https://api.onedrive.com/v1.0"

# call api
$Response = Invoke-RestMethod -Headers $Header -Method GET -Uri "$ApiRootUrl/drive/shared"

RETURN $Response.value
}

# call method to do job
$Results = List-SharedItem -ClientId $ClientId -SecrectKey $SecrectKey -RedirectURI $RedirectURI

# print results
$Results | ForEach-Object {
Write-Host "ID: $($_.id)"
Write-Host "Name: $($_.name)"
Write-Host "ParentReference: $($_.parentReference)"
Write-Host "Size: $($_.size)"
Write-Host "WebURL: $($_.webUrl)"
Write-Host
}

有关完整的说明,请参见 https://gallery.technet.microsoft.com/How-to-use-OneDrive-Rest-5b31cf78中的示例。

关于powershell - 与外部用户共享的Onedrive API列表文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36634960/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com