groupId="groupObjId"
sp_list=("myapp01" "myapp02" "myapp03")
for sp_name in "${sp_list[@]}"
do
spObjId=$(az ad sp list --display-name "$sp_name" --query '[0].id' --output tsv)
if [ -n "$spObjId" ]; then
az ad group member add --group $groupId --member-id $spObjId
if [ $? -eq 0 ]; then
echo "Service Principal with Name: $sp_name (Object ID: $spObjId) added to AAD Group successfully."
else
echo "Failed to add Service Principal with Name: $sp_name (Object ID: $spObjId) to AAD Group."
fi
else
echo "Service Principal with Name: $sp_name not found."
fi
done
1条答案
按热度按时间g2ieeal71#
为了向AAD组添加多个服务主体,我在我的环境中运行了下面的bash脚本,得到了如下的响应:
回复:
当我在Portal中进行相同检查时,服务主体已成功作为成员添加到Azure AD组,如下所示: