Hi @consultantlk ,
I know this topic has already been marked as solved, but if you're still looking for a solution to this (or for anyone else looking for a solution to this), I wanted to provide an update.
Using Windows PowerShell 5.1.xxx, you can add users in bulk into any Power Platform environment. To do this, first create a CSV file with the email address of each user.
Next, make sure you are using Windows PowerShell 5.1.xxx by running the following command:
$PSVersionTable
If this returns any version other than 5.1.xxx, you will need to install or switch to Windows PowerShell version 5.1.xxx before continuing.
Once you've created the CSV file and confirmed that you're using Windows PowerShell 5.1.xxx, next you'll need to install the appropriate PowerApps modules by opening Windows PowerShell as an administrator and running the following commands:
Install-Module -Name Microsoft.PowerApps.Administration.PowerShell
Install-Module -Name Microsoft.PowerApps.PowerShell -AllowClobber
Once these modules have been installed successfully, you can then run the following PowerShell script to add the users into the environment:
# Add users to Power Platform environment
$CsvPath = '.\NewUsers.csv' # Replace with relative/absolute path to your CSV file
$PowerAppsEnvName = 'example' # Replace with your Power Platform environment name
$PowerAppsEnvGuid = (Get-AdminPowerAppEnvironment $PowerAppsEnvName).EnvironmentName
foreach($User in (Import-Csv -Path $CsvPath)) {
$UserEmail = $User.'Email' # Replace 'Email' with the CSV column heading
Write-Output "Attempting to add $($UserEmail) to $($PowerAppsEnvName)..."
$UserId = (Get-AzADUser -ObjectId $UserEmail).Id
try {
Add-AdminPowerAppsSyncUser -EnvironmentName $PowerAppsEnvGuid -PrincipalObjectId $UserId
Write-Output "$($UserEmail) added to $($PowerAppsEnvName)!"
}
catch {
Write-Output "$($UserEmail) is already a member of $($PowerAppsEnvName)."
}
}
This script will not only attempt to add each user into your Power Platform environment, but will also let you know the result. Once complete, all new users should now be in your Power Platform environment.
Key Points Worth Noting:
- The PowerApps modules only work with Windows PowerShell 5.1.xxx (unfortunately)
- You must run Windows PowerShell as an administrator
- If you see an error related to the 'AcquireToken' method, double-check that you are running Windows PowerShell as an administrator (I've made this mistake!)
Hope this helps!