web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Unanswered

Force Sync users using PowerShell

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hello!

Based on the documentation on https://learn.microsoft.com/en-us/power-platform/admin/troubleshooting-user-needs-read-write-access-organization#adding-or-refreshing-users-on-demand we can force sync users on Demand. This might seem helpful on certain situations:

  • We have a large number of users that we need to sync and we can't wait for PPAC to trigger
  • A high number of users are being added to the security groups and we need provide access immediately, and we can't go on a one-by-one basis on PPAC

Without delays, this is a sample script that can be used for this purpose:

$EnvironmentName = 'EnvironmentID'
$groupName='display name of the group'

#Get environment
$Environment = Get-AdminPowerAppEnvironment -EnvironmentName $EnvironmentName
if($Environment)
{
  #AzureAD part. Connect to azure and retrieve enabled users
  Connect-AzureAD

  #Using SecurityGroups
  $Group = Get-AzureADGroup | Where { $_.DisplayName -eq $groupName }
  $users = Get-AzureADGroupMember -ObjectId $group.ObjectId

  #Querying directly the AzureAD
  $users = Get-AzureADUser -all $true | where {$_.accountenabled -eq $true}
  $users
  
  #iterating through the array of users
  foreach ($user in $users)
  {
    #Force sync on each user
    Add-AdminPowerAppsSyncUser -EnvironmentName $Environment.EnvironmentName -PrincipalObjectId $user.ObjectId
  }
}

If we know the EnvironmentID, we can trigger the sync by running the add-adminpowerappsyncuser documented on https://learn.microsoft.com/en-us/powershell/module/microsoft.powerapps.administration.powershell/add-adminpowerappssyncuser?view=pa-ps-latest  the other part, would require to connect to AzureAD.  ON this scripts, I'm using 2 possibilities:

- Getting all users on the Domain that are active, through the command get-azureaduser.  By using the parameter -all $true, I'm ensuring I'm querying the whole directory and retrieving all elements (and not batches of 5000 for example).  I'm also using a where condition to specify to retrieve only enabled users.

- Getting all users on an AzureAD SecurityGroup.  For this scenario, First I need the security group name (original parameter).   After running the Get-azureadGroup (with a condition to retrieve the one with the exact same name), I can run a second command to get all members of this security group:  get-azureadGroupMember that receives as a parameter the ObjectID of the security group.

The beauty of this approach is that:

  1. I can build my own script to force sync users on demand
  2. I can add some custom logic for example, to write a log to indicate when was the user processed, or send email notification once it completes
  3. I can add some additional lines, to make validations (if user exists, if there are users that fulfill the condition, etc)
  4. If there's any error, I can capture it and investigate (or provide it to Microsoft on a Support case)

Regards,

I have the same question (0)

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
11manish Profile Picture

11manish 178

#2
ManoVerse Profile Picture

ManoVerse 149 Super User 2026 Season 1

#3
Jimmy Passeti Profile Picture

Jimmy Passeti 57 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans