office365 - Powershell script to view all OneDrive files and who has access to them -
i'm pretty new powershell , wanted know if there way pull files onedrive , see has access them?
i hoping find easier way see whether or not file shared , if is, shared internally , externally.
as of right now, know if go through each user account, can see information. i'm curious know if there faster way that.
you can call onedrive list shared file rest api finish job.
you need register application proper access onedrive according https://dev.onedrive.com/app-registration.htm
then can make use code below.
$clientid = "<your application client id>" # application clientid $secrectkey = "<your application key>" # secrect key application $redirecturi = "<your web app redirect url>" # re-direct url of application function list-shareditem { [cmdletbinding()] param ( [parameter(mandatory=$true)][string]$clientid, [parameter(mandatory=$true)][string]$secrectkey, [parameter(mandatory=$true)][string]$redirecturi ) # import utils module import-module ".\onedriveauthentication.psm1" # token $token = new-accesstokenandrefreshtoken -clientid $clientid -redirecturi $redirecturi -secrectkey $secrectkey # can store token somewhere later usage, token expired # if token expired, please call update-accesstokenandrefreshtoken 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 -uri "$apirooturl/drive/shared" return $response.value } # call method 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 }
for complete instructions, can see sample in https://gallery.technet.microsoft.com/how-to-use-onedrive-rest-5b31cf78
Comments
Post a Comment