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?

Graph PowerShellでSharePointリストの参照列に値を登録する

Last updated at Posted at 2025-01-24

やりたいこと

タイトル通りです。前回の記事ではPnP PowerShellでしたが、今回の記事はGraph PowerShell版の備忘録として記事に残します。

事前準備

ClientリストとProductリストを用意しておきます。Productリストの「RefClientName」列を参照列として、Clientリストの「ClientName」列でリレーションシップを設定しています。

image.png

image.png

PowerShellの実行コマンド

結論、実行コマンドは以下です。
「LookupId」を参照列名に付与することが動作の鍵となります。

Connect-MgGraph -Scopes "User.Read.All", "Group.ReadWrite.All"

$clientName = "テスト株式会社"
$productName = "テスト製品"
$clientListName = "Client"
$productListName = "Product"
$siteName = "{サイト名}"

$siteId = Get-MgSite -Search "$siteName"
$productListId = Get-MgSiteList -SiteId $siteId.Id -Filter "DisplayName eq '$clientListName'"
$clientListId = Get-MgSiteList -SiteId $siteId.Id -Filter "DisplayName eq '$productListName'"

$clientListItem = Get-MgSiteListItem -SiteId $siteId.Id -ListId $clientListId -Filter "fields/ClientName eq '$clientName'"
$params = @{
    fields = @{
        ProductName          = $productName
        RefClientNameLookupId = $clientListItem.Id
    }
}

New-MgSiteListItem -SiteId $siteId.Id -ListId $productListId -BodyParameter $params
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?