-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddOwnerToFlows.ps1
More file actions
70 lines (56 loc) · 3.02 KB
/
AddOwnerToFlows.ps1
File metadata and controls
70 lines (56 loc) · 3.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<#
.SYNOPSIS
Script to add owners to existing Flows ( Microsoft Power Automate)
.DESCRIPTION
This script comes handy if you would like to add owners to existing Flows ( Microsoft Power Automate).
This script uses PowerShell Modules for Power Apps and Power Automate
https://docs.microsoft.com/en-us/power-platform/admin/powerapps-powershell
.EXAMPLE
.\AddOwnerToFlows.ps1
.PARAMETER
.
.NOTES
*************************************************************************
* Copyright (C) 2020-2021 Prashant G Bhoyar and Withum Digital, LLC.
* All Rights Reserved.
*
* NOTICE: All information contained herein is, and remains
* the property of Prashant G Bhoyar and Withum Digital, LLC.
* The intellectual and technical concepts contained
* herein are proprietary to Prashant G Bhoyar and Withum Digital
* and may be covered by U.S. and Foreign Patents, patents in
* process, and are protected by trade secret or copyright law.
* Dissemination of this information or reproduction of this material
* is strictly forbidden unless prior written permission is obtained
* from Prashant G Bhoyar and Withum Digital, LLC.
*************************************************************************
#>
### To install the required PowerShell Modules
#Install-Module -Name Microsoft.PowerApps.Administration.PowerShell
#Install-Module -Name Microsoft.PowerApps.PowerShell -AllowClobber
#Install-Module -Name AzureAD
###Email address of the account that needs to be added as owner in all Flows
$emailAddress = "demo@pgbhoyar.onmicrosoft.com";
###To Login with Flow Admin Account ( Right Now Global Admin Account) of the Tenant where we are running this script.
Add-PowerAppsAccount
Connect-AzureAD
## This will give you default environment in case you have multiple environments. To get non-default environment use the string from DisplayName of the environment.
## If you don't know the environment displayName, Type cmdlet Get-FlowEnvironment to get the information of all the available environments
$flowEnvironment = Get-FlowEnvironment *default*
Write-Host "Flow Environment ID is " $flowEnvironment.EnvironmentName
$userID = Get-AzureADUser -ObjectID $emailAddress | Select-Object ObjectId
Write-Host "UserID is " $userID.objectId
$flows = Get-AdminFlow | Select-Object FlowName, DisplayName
foreach($flow in $flows){
Write-Host "Adding Owner in the Flow "$flow.DisplayName
Write-Host "Adding Owner in the Flow "$flow.FlowName
try{
## Sample cmdlet
#Set-AdminFlowOwnerRole -PrincipalType Group -PrincipalObjectId <Guid> -RoleName CanEdit -FlowName <Guid> -EnvironmentName Default-<Guid>
Set-AdminFlowOwnerRole -PrincipalType User -PrincipalObjectId $userID.objectId -RoleName CanEdit -FlowName $flow.FlowName -EnvironmentName $flowEnvironment.EnvironmentName
Write-Host "Added Owner" $emailAddress " to the Flow " $flow.DisplayName
}
Catch [System.Exception]{
Write-Host $_.Exception.Message
}
}