LoginSignup
0
1

More than 3 years have passed since last update.

PowerShellでSharePointOnlineのドキュメントからファイルをダウンロードする

Last updated at Posted at 2019-09-12
spodownload.ps1
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client") | Out-Null
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime") | Out-Null

$pass = convertto-securestring "password" -AsPlainText -Force
$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials("userAccount", $pass)
$cookieValue = $credentials.GetAuthenticationCookie("https://xxxxxxx.sharepoint.com/sites/site/")

$cookieValue = $cookieValue.Replace("SPOIDCRL=","")
$cookie = New-Object System.Net.Cookie
$cookie.Name = "SPOIDCRL"
$cookie.Value = $cookieValue

$cookieContainer = New-Object System.net.CookieContainer
$cookieContainer.Add("https://xxxxxxx.sharepoint.com/sites/site/",$cookie)

$request = [System.Net.WebRequest]::Create("https://xxxxxxx.sharepoint.com/sites/site/Shared%20Documents/test.xlsx")
$request.CookieContainer = $cookieContainer
$response = $request.GetResponse()
$responseStream = $response.GetResponseStream()

$outputFile = [System.IO.File]::Create("C:\work\test.xlsx")
$Buffer = New-Object Byte[] 1024
Do {
    $BytesRead = $responseStream.Read($Buffer, 0, $Buffer.Length)
    $outputFile.Write($Buffer, 0, $BytesRead)
} While ($BytesRead -gt 0)

$responseStream.Close()
$responseStream.Dispose()

$outputFile.Flush()
$outputFile.Close()
$outputFile.Dispose()

参考

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1