Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
Hello All,
Daily I want to automate the Powershell script for extracting Power BI Security AD groups using service principal. Few days back we are able to automate the script but suddenly yesterday onwards i am getting the below error.
PowerShell script I am using to extract Power BI security AD groups which are added to the Workspace as given below
$AppId = "AppID"
$TenantId = "TenantID"
$ClientSecret = "ClientSecret"
$MsalToken = Get-MsalToken -TenantId $TenantId -ClientId $AppId -ClientSecret ($ClientSecret | ConvertTo-SecureString -AsPlainText -Force)
#Connect to Graph using access token
Connect-graph -AccessToken $MsalToken.AccessToken
$Groups = Get-MgGroup -all|Where-Object {($_.DisplayName -like 'a-PBIxx-*')}|Select-Object Id,DisplayName
foreach ($Group in $Groups)
{
$Group_GUID = $Group.Id
$Group_DisplayName = $Group.DisplayName
$GroupMembers = get-mggroupmember -GroupId $Group_GUID -All
foreach ($GroupMember in $GroupMembers)
{
$users = get-mguser -userid $GroupMember.id
$Properties = @{"GroupDisplayName"=$Group_DisplayName;
"MemberDisplayName"=$users.DisplayName;
"MemberEmail"=$users.UserPrincipalName;
"GUID"=$Group_GUID;}
$Obj = New-Object -TypeName PSObject -Property $Properties
Write-Output $Obj | select GUID,GroupDisplayName,MemberDisplayName,MemberEmail |Export-Csv -Path File path/.csv
}
}
Get-Mggroup -all | Where-Object {($_.DisplayName -like 'a-PBIxx-*')} | ? {(Get-Mggroupmember -GroupId $_.Id).count -eq 0 } | Select-Object Id,DisplayName|Export-Csv -Path File path/.csv -NoTypeInformation
$csvData = Import-Csv -Path File path/.csv" | Select-Object @{n='GUID';e={$_.Id}},@{n='GroupDisplayName';e={$_.DisplayName}},MemberDisplayName,MemberEmail
$csvData | Export-Csv -Append -NoTypeInformation -Path "File path/.csv"
Thanks in advance!
This is not Power BI related. You will have more luck when you post in the PowerShell forums.
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!
Check out the November 2025 Power BI update to learn about new features.