forked from jameswh3/MW-Toolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGet-CopilotsAndComponentsFromAllEnvironments.ps1
More file actions
43 lines (38 loc) · 2.17 KB
/
Get-CopilotsAndComponentsFromAllEnvironments.ps1
File metadata and controls
43 lines (38 loc) · 2.17 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
#Requires -Modules Microsoft.PowerApps.Administration.PowerShell
#Requires -Modules Microsoft.PowerApps.PowerShell
function Get-CopilotsAndComponentsFromAllEnvironments {
[CmdletBinding()]
param (
[Parameter(Mandatory=$false, Position=0, HelpMessage="Enter the Azure AD application client ID")]
[string]$ClientId,
[Parameter(Mandatory=$false, Position=1, HelpMessage="Enter the client secret for authentication")]
[string]$ClientSecret,
[Parameter(Mandatory=$false, Position=3, HelpMessage="Enter your tenant domain (e.g., contoso.onmicrosoft.com)")]
[string]$TenantDomain
)
BEGIN {
$environmentData=Get-AdminPowerAppEnvironment | Where-Object -Property "CommonDataServiceDatabaseType" -eq "Common Data Service for Apps"
}
PROCESS {
foreach ($e in $environmentData) {
$orgUrl=$e.Internal.Properties.linkedEnvironmentMetadata.instanceApiUrl
#get list of agents/copilots/bots
write-host "Getting bots and components for environment: $($e.DisplayName) - $($e.EnvironmentName) - $orgUrl"
$bots=Get-CopilotAgentsViaAPI -ClientId $clientId `
-ClientSecret $clientSecret `
-OrgUrl $orgUrl `
-TenantDomain $TenantDomain `
-FieldList "botid,componentidunique,name,configuration,createdon,publishedon,_ownerid_value,_createdby_value,solutionid,modifiedon,_owninguser_value,schemaname,_modifiedby_value,_publishedby_value,authenticationmode,synchronizationstatus,ismanaged"
#get list of bot components
write-host "Getting bot components for environment: $($e.DisplayName) - $($e.EnvironmentName) - $($e.EnvironmentUrl)"
$components=Get-BotComponentsViaAPI -ClientId $clientId `
-ClientSecret $clientSecret `
-OrgUrl $orgUrl `
-TenantDomain $TenantDomain `
-FieldList "botcomponentid,componenttype,data,description,filedata,filedata_name,name,schemaname,createdon,_createdby_value,modifiedon,_modifiedby_value,_parentbotid_value"
}
}
END {
return @($bots,$components)
}
}