Help us understand the problem. What is going on with this article?

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

More than 3 years have passed since last update.

目的

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

sharepointer
Office 365 や、Azure やってます
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away