LoginSignup
5
9

More than 5 years have passed since last update.

PowerShell で、SharePoint Online の リストとアイテムの情報を書き出してみた

Last updated at Posted at 2017-05-18

目的

SharePoint Online では、Client Side Object Model(CSOM)を使って、
色々な情報を抜き出したり、書き込んだりすることができる。
これを使うと、簡単に管理作業が出来るので、これから色々なスクリプトを書いてみる。

CSOMに関することは、サポートチームのblogで、
https://blogs.technet.microsoft.com/sharepoint_support/2014/10/19/sharepoint-online-powershell/

事前準備

以下のインストール

サンプル

設定する項目は、以下の二か所

\$SiteCollectionUrl :サイトコレクションのURL
\$Account :管理者権限のアカウント
\$objListName :リストの表示名

 # Read CSOM
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client") | Out-Null
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime") | Out-Null

# SiteCollection URL 
$SiteCollectionUrl = "https://tenant-name.sharepoint.com" 
# $SiteCollectionUrl = "https://tenant-name.sharepoint.com/sites/subsite" 

# Account
$Account = "administratorsName@tenant-name.onmicrosoft.com" 
$SecurePassword = Read-Host -Prompt "Enter Your Password." -AsSecureString

# Create Credential
$Credential = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Account, $SecurePassword) 

# Create Context
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteCollectionUrl)
$Context.Credentials = $credential

$objListName = "ドキュメント"

# Create List object
$objList = $Context.Web.Lists.GetByTitle($objListName)
$Context.Load($objList)
$Context.ExecuteQuery()

Write-Host "list Title : " $objList.Title
Write-Host "list BaseType : " $objList.BaseType
Write-Host "list Created : " $objList.Created

$query = New-Object Microsoft.SharePoint.Client.CamlQuery
$query.ViewXml = ""

$objListItems = $objList.getItems($query)
$Context.Load($objListItems)
$Context.ExecuteQuery()

Write-Host ""

foreach($item in $objListItems)
{
    Write-Host  $item.Id.ToString() `t $item["FileLeafRef"] `t $item["Editor"].LookupValue `t $item["Modified"]

}

# Dispose Context
$Context.Dispose()

参考

クエリ スキーマ(CAML)
https://msdn.microsoft.com/ja-jp/library/ms467521(v=office.14).aspx
SPBuiltInFieldId メンバ (Microsoft.SharePoint)
https://msdn.microsoft.com/ja-jp/library/microsoft.sharepoint.spbuiltinfieldid_members(v=office.12).aspx

5
9
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
5
9