我正在使用PowerShell和OneDrive API来实现这一目标。我可以获得所有文件夹/文件/等,但我很难找到我可以列出已共享某个文件的所有用户的位置。我的范围已包含wl.skydrive_contacts,我已经使用API列出了所有文件夹/文件。谁能给我一些见解?
答案 0 :(得分:1)
您可以使用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
中查看示例