Last active
June 13, 2024 18:37
-
-
Save joerodgers/f47b196ed87b9667cf43572a033e7e37 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#requires -modules "Microsoft.Xrm.Data.Powershell" | |
$ErrorActionPreference = [System.Management.Automation.ActionPreference]::Stop | |
$credential = [PSCredential]::new( 'powerplatfromadmin@contoso.com', ( '<password>' | ConvertTo-SecureString -AsPlainText -Force) ) | |
$environments = Get-CrmOrganizations -OnLineType Office365 -Credential $credential | |
$timestamp = Get-Date -Format FileDateTime | |
foreach( $environment in $environments | Sort-Object FriendlyName ) | |
{ | |
try | |
{ | |
Write-Host "[$(Get-Date)] - Scanning: $($environment.FriendlyName )" | |
$connection = Get-CrmConnection -OrganizationName $environment.UrlHostName -OnLineType Office365 -Credential $credential -ErrorAction Stop | |
$rows = Get-CrmRecords -EntityLogicalName "bot" -AllRows -conn $connection | |
if( $rows.Count -eq 0 ) { continue } | |
$details = foreach( $record in $rows.CrmRecords ) | |
{ | |
$r = Get-CrmRecord -Id $record.botid -EntityLogicalName "bot" -Fields * -conn $connection | |
$owner = Get-CrmRecord -Id $r.owninguser_Property.Value.Id -EntityLogicalName "systemuser" -Fields domainname -conn $connection | |
$r | Select-Object *, @{ Name="OwnerUserName"; E={ $owner.domainname }} | |
} | |
$records = $details | Sort-Object name | Select-Object ` | |
name, | |
ownerUserName, | |
ownerid, | |
createdby, | |
createdon, | |
@{Name="EnvironmentName"; E={ $environment.FriendlyName}}, | |
@{Name="EnvironmentHostName"; E={ $environment.UrlHostName}}, | |
@{Name="GenerativeActionsEnabled"; E={ $json = $_.configuration | ConvertFrom-Json; if( -not [string]::IsNullOrEmpty($json.settings.GenerativeActionsEnabled)){ return $json.settings.GenerativeActionsEnabled }else{ return $false }}}, | |
@{Name="AllowAIGeneralKnowledge "; E={ $json = $_.configuration | ConvertFrom-Json; if( -not [string]::IsNullOrEmpty($json.aISettings.useModelKnowledge)) { return $json.aISettings.useModelKnowledge }else{ return $false }}}, | |
accesscontrolpolicy, | |
authenticationmode, | |
authenticationtrigger, | |
botid, | |
componentidunique, | |
componentstate, | |
createdonbehalfby, | |
iscustomizable, | |
ismanaged, | |
language, | |
logicalname, | |
modifiedby, | |
modifiedon, | |
modifiedonbehalfby, | |
owningbusinessunit, | |
schemaname, | |
solutionid, | |
statecode, | |
statuscode | |
$records | Export-Csv -Path "copilotbots_$timestamp.csv" -NoTypeInformation -Append | |
} | |
catch | |
{ | |
Write-Host "Failed to scan environment: $($environment.FriendlyName). Error: $_" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment