0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

PnP PowerShellでSharePointリストのアイテムにアクセス権限を付与する

Last updated at Posted at 2025-01-25

やりたいこと

SharePointリストのアイテム単位でアクセス権限を設定する場合、通常は「アクセス許可の管理」からユーザーまたはグループに編集権限や閲覧権限を割り当てますが、これをPowerShellで実行したいと考えています。

sharepoit-list-item-access.png

image.png

実装方法

実装方法はPnP PowerShellコマンドレットのドキュメントに記載されています。

PowerShellの実行コマンド

結論、実行コマンドは以下です。
ClientリストのClientName列に「テスト株式会社」と設定されているアイテムに対して、特定のユーザーに編集権限を割り当てます。

# SharePointサイトに接続
$siteUrl = "https://{tenant_name}.sharepoint.com/sites/{site_name}"
Connect-PnPOnline -Url $siteUrl -UseWebLogin

# ClientリストのアイテムにEdit権限を割り当てる
$user = "{アクセス権限を割り当てるユーザーを指定する}"
$clientName = "テスト株式会社"
$listName = "Client"
$camlQuery = @"
<View>
  <Query>
    <Where>
      <Eq>
        <FieldRef Name='ClientName' />
        <Value Type='Text'>$clientName</Value>
      </Eq>
    </Where>
  </Query>
</View>
"@

$items = Get-PnPListItem -List $listName -Query $camlQuery
$itemId = $items | ForEach-Object { $_.Id }
Set-PnPListItemPermission -List $listName -Identity $itemId -User $user -AddRole "投稿"
0
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?