forked from jameswh3/MW-Toolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGet-BotComponentsViaAPI.ps1
More file actions
40 lines (36 loc) · 1.94 KB
/
Get-BotComponentsViaAPI.ps1
File metadata and controls
40 lines (36 loc) · 1.94 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
function Get-BotComponentsViaAPI {
[CmdletBinding()]
param (
[Parameter(Mandatory=$true, Position=0, HelpMessage="Enter the Azure AD application client ID")]
[string]$ClientId,
[Parameter(Mandatory=$true, Position=1, HelpMessage="Enter the client secret for authentication")]
[string]$ClientSecret,
[Parameter(Mandatory=$true, Position=2, HelpMessage="Enter your Dynamics 365 organization URL (e.g., contoso.crm.dynamics.com)")]
[string]$OrgUrl,
[Parameter(Mandatory=$true, Position=3, HelpMessage="Enter your tenant domain (e.g., contoso.onmicrosoft.com)")]
[string]$TenantDomain,
[Parameter(Mandatory=$false, HelpMessage="Specify additional fields to retrieve")]
[string[]]$FieldList="botcomponentid,componenttype,data,description,filedata,filedata_name,name,schemaname,createdon,_createdby_value,modifiedon,_modifiedby_value,_parentbotid_value"
)
BEGIN {
# Remove https:// prefix from OrgUrl if present
if ($OrgUrl.StartsWith("https://")) {
$OrgUrl = $OrgUrl.Substring(8)
}
$tokenUrl = "https://login.microsoftonline.com/$TenantDomain/oauth2/v2.0/token"
$token = Invoke-RestMethod -Uri $tokenUrl `
-Method Post `
-Body @{grant_type="client_credentials"; client_id="$ClientId"; client_secret="$ClientSecret"; scope="https://$OrgUrl/.default"} `
-ContentType 'application/x-www-form-urlencoded'
}
PROCESS {
#get list of agents/copilots/bots
<#$response=Invoke-RestMethod -Uri "https://$OrgUrl/api/data/v9.2/botcomponents?`$select=$FieldList" `
-Headers @{Authorization = "Bearer $($token.access_token)"}#>
$response=Invoke-RestMethod -Uri "https://$OrgUrl/api/data/v9.2/botcomponents" `
-Headers @{Authorization = "Bearer $($token.access_token)"}
}
END {
return $response.value
}
}