LoginSignup
0
0

More than 1 year has passed since last update.

【Azure】CloudshellからAdd-AzureADGroupMemberを実行できない

Last updated at Posted at 2022-04-15

【2022/4/27追記】
2022/4/27に確認したところ、
CloudshellからもAdd-AzureADGroupMemberを実行できるようになっていましたが、
備忘として記事は残します。

AzureのCloudshellから、Add-AzureADGroupMemberを実行したところ、
よくわからないエラーに遭遇したので、対応方法を備忘録として残します。

【事象】
AzureのCloudshellから以下形式でAdd-AzureADGroupMemberを実行した際、エラーが発生し、ユーザをグループに追加できません。(2022/4/15時点)
なお、2週間ほど前は問題なく実行できていました。-

Cloudshell上でAdd-AzureADGroupMemberを実行した際のエラー
Add-AzureADGroupMember -ObjectId "グループのオブジェクトID" -RefObjectId "ユーザのオブジェクトID"

Add-AzureADGroupMember: Error occurred while executing AddGroupMember 
Code: Request_BadRequest
Message: The URI 'https://graph.windows.net//xxx/directoryObjects/xxx' is not valid since it is not based on 'https://graph.windows.net/83dee3a9-071b-4190-b93f-823ba60f7a75/'.
RequestId: 928fd737-97d9-474c-8584-218751281f04
DateTimeStamp: Fri, 15 Apr 2022 12:34:36 GMT
HttpStatusCode: BadRequest
HttpStatusDescription: Bad Request
HttpResponseStatus: Completed

エラーに表示されたURLを叩くと、
Request_DataContractVersionMissingと記載されていました。

リンク先の記載内容
<error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<code>Request_DataContractVersionMissing</code>
<message xml:lang="en">The specified api-version is invalid. The value must exactly match a supported version.</message>
</error>

【回避策①:az ad group member addコマンドを使用】
az ad group member addコマンドであれば、
従来通りCloudshellから実行可能です。
実効結果はAdd-AzureADGroupMemberと同じです。

az ad group member addコマンドを使用
az ad group member add --group "グループのオブジェクトID" --member-id "ユーザのオブジェクトID" 

ちなみに2022/4/15時点だと以下警告が表示されます。
Microsoft Graph APIへの移行に伴い、
az ad group member addは--additional-propertiesオプションが削除される予定とのことです。

The underlying Active Directory Graph API will be replaced by Microsoft Graph API in Azure CLI 2.37.0. 
Please carefully review all breaking changes introduced during this migration: https://docs.microsoft.com/cli/azure/microsoft-graph-migration

【回避策②:ローカル環境のPowershellから実行】
ローカル環境のPowershellにて、azureadモジュールをインストール後、
Add-AzureADGroupMemberを実行すれば問題なくユーザをグループに追加できます。

ローカル環境のPowershellからAdd-AzureADGroupMemberを実行
import-module azuread
Connect-AzureAD
Add-AzureADGroupMember -ObjectId "グループのオブジェクトID" -RefObjectId "ユーザのオブジェクトID"

【Add-AzureADGroupMemberが実行できなくなった原因】
ローカルのPowershellからはAdd-AzureADGroupMemberコマンドを実行できているので、
Cloudshell側の環境に原因があると思われますが、具体的な原因については不明です。
現状はaz ad group member addコマンドに切り替えるのが一番コストが少ない対応方法かと思います。

Cloudshellは便利ですが、MS社の都合で環境が変化する点を留意したうえで使用する必要があると改めて感じました。

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