1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ドキュメントライブラリのカスタム列を更新するPowerShell

Posted at

###ドキュメントライブラリでまとめてフォルダやファイルをアップロードした後にカスタム列のデータを更新するPowerShell
テストデータの作成などで

#ロード
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client")
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime")

#ユーザーID
$User = "user@xxxxx.onmicrosoft.com"

#更新対象ドキュメントライブラリがあるサイトのURL
$SiteURL = "https://xxxxx.sharepoint.com/sites/xxx/"

#更新対象ライブラリの名称
$DocLibName = "test"

#パスワードを入力
$Password = Read-Host -Prompt "Please enter your password" -AsSecureString

#対象のサイトの読み込み
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($User,$Password)
$Context.Credentials = $Creds

#対象のライブラリの読み込み
$List = $Context.Web.Lists.GetByTitle($DocLibName)
$Context.Load($List.RootFolder)
$Context.ExecuteQuery()

$camlQuery = new-object Microsoft.SharePoint.Client.CamlQuery
#再帰的に取得(フォルダ内部のデータも対象)
$camlQuery.ViewXml = "<View Scope='RecursiveAll'><Query><Where></Where></Query></View>"
		
$listItems = $list.GetItems($camlQuery)
$context.Load($listItems)
$context.ExecuteQuery()

#無条件に読み込み、存在するデータ分一律の値でUpdate
foreach($listItem in $listItems){
    $listItem["customColumn"] = "test"  #件名
    $listItem["startDate"] = Get-Date -Format “yyyy/MM/dd” #開始予定日 
    $listItem["endDate"] = “2018/12/31” #終了予定日

    $listItem.Update(); 
    $Context.ExecuteQuery();  
}

1
2
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
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?