我想在 Azure Active Directory 中向用戶添加所有可能的組成員身份,但是組太多,所以我不想手動執行,是否有任何腳本或按鈕可以快速執行此操作?
uj5u.com熱心網友回復:
? 是的,您當然可以通過powershell 腳本執行此操作,您需要將Azure AD 中存在的所有組的詳細資訊匯出到CSV 檔案或控制臺。然后呼叫每個組將powershell命令中指定物件ID的所述用戶添加到每個組。請在 Azure AD 中存在的所有組中為指定用戶找到以下準備和測驗的 powershell 腳本。
Powershell腳本: -
Connect-AzureAD
$groups=Get-AzureADGroup | Select-Object ObjectID
foreach($group in $groups) {Add-AzureADGroupMember -ObjectId $group.ObjectId -RefObjectId "f08cdf62-6d20-4b65-bdd8-33f84c61802f"} ’
? 結果: -

請在下面找到 Microsoft 檔案以供參考:-
https://docs.microsoft.com/en-us/azure/active-directory/enterprise-users/groups-settings-v2-cmdlets#add-members
uj5u.com熱心網友回復:
在 powershell 中嘗試這個安裝 azure AD 模塊
PS C:\Windows\system32> install-module azuread
PS C:\Windows\system32> import-module azuread
您可以通過以下方式進行驗證:
PS C:\Windows\system32> get-module azuread
現在將你的 powershell 連接到目錄
PS C:\Windows\system32> Connect-AzureAD
它將提示您輸入要用于訪問目錄的憑據并回傳確認以顯示會話已成功連接到您的目錄:
Account Environment Tenant ID
------- ----------- ---------
[email protected] AzureCloud 23b5ff1e-3402-800c-823c-3f…
要從您的目錄中檢索現有組,請使用 Get-AzureADGroups cmdlet
$groups= get-azureadgroup
foreach ($group in $groups)
{
Add-AzureADGroupMember -ObjectId $group.ObjectId -RefObjectId <user reference id>
}
替換用戶參考 ID,您可以使用 Get-AzureADUser 來獲取
uj5u.com熱心網友回復:
Kartik 和 Vineesh 的答案非常好,但是如果你想獲得所有可用的組并且你已經是某些組的成員,你應該使用這個腳本
try
{
Connect-AzureAD
$groups=Get-AzureADGroup -All $true ` | Select-Object ObjectID
foreach($group in $groups) {
$Members = $group | Get-AzureADGroupMember -All $true
$IsUserInGroup = $Members.ObjectID -contains "your objectId"
if ($IsUserInGroup -eq $false)
{
Add-AzureADGroupMember -ObjectId $group.ObjectId -RefObjectId "your
objectId"
}
}
}
catch
{
Write-Error $_.Exception.ToString()
Read-Host -Prompt "The above error occurred. Press Enter to exit."
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/446799.html
上一篇:二頭肌-資料工廠身份屬性
