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?

Entra IDのセキュリティグループをPowerShellで作る

Last updated at Posted at 2025-05-14

動機

Entra ID で、セキュリティグループをそれなりに数作らなくてはいけなかったが、一気につくるわけではないしと、Entra管理センターでぽちぽちとやっていたら、辛くなってきたので、PowerShellでやることにした

使うことにしたコード

環境

  • PowerShell 7.5
  • Microsoft Entra PowerShell モジュール 1.0.7
New-EntraGroup/Add-EntraGroupOwner
# 基本的に単発なので、Excelで下記のとおり作成するグループごとに作る予定
New-EntraGroup -DisplayName "グループ名" -MailEnabled $false -SecurityEnabled $true -MailNickname "NotSet" | Select * | %{Add-EntraGroupOwner -GroupId $_.Id -OwnerId '所有者にしたいユーザーのObjectId'}

反省

  • Preview版のEntraモジュールが入れっぱなしだった
  • AzureADモジュールが入っていたおかげで、競合していたらしく、-GroupId -OwnerIdでは通らず、Add-EntraGroupOwner -ObjectId GroupID -RefObjectID UserIDとしないといけなくて、調べるのにかなり時間をかけてしまった。

ついでに

DisplayNameでグループを絞り込みかけるときは、前方一致で以下の通りした。Containsはサポートしていないので、部分一致したい場合は、一度全体を取得した後、絞り込みかける必要あり。

Get-EntraGroup
Get-EntraGroup -Filter "startsWith(DisplayName, 'prefix')"

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?