Décode l'informatique
PowerShell PowerApps Control Value

PowerShell script to automatically retrieve the property value ​​of Power Apps controls

PowerShell script to automatically retrieve the property value ​​of Power Apps controls.

PowerShell PowerApps Control Value
PowerShell PowerApps Control Value

A CSV file is generated with all the properties and their value.

To make this script work properly, the Power Apps application must be registered locally on the computer: File > Save As > This Computer.

I apologise. This program is not perfect. It is not recursive. It stops at two levels: screens and 1st level controls. Controls that are grouped, datacards, controls inside galleries and so on are therefore not supported in this release. I’m working on a “big” project to automate process with Power Apps and Power Automate. So, free time is scarce.

<#
MAKE A BACKUP OF YOUR DATA BEFORE STARTING THE PROGRAM!
Use at your own risk.
Remember: Set-ExecutionPolicy RemoteSigned
#>

Clear-Host

# Personal settings
$importPath = "directory_where_you_saved_your_msapp"
# e.g.: "C:\Scripts\msapp"
$exportPath = "directory_where_csv_file_will_be_stored"
# e.g.: "C:\Scripts\controls"
$appName = "name_of_your_app_file_once_it_is_saved_w/o_extension_msapp"
# e.g.: "HelloWorld"

# Calculated settings and others
$exportFile = "$exportPath\$appName.csv"
$allObjects = @()

# Deletion of previous results from previous runs
if (test-path $exportfile) {
Remove-Item -path $exportfile}
if (Test-Path "$importPath\$appName.zip") {
Remove-Item -path "$importPath\$appName.zip"}
if (Test-Path "$importPath\$appName.expand") {
Remove-Item -path "$importPath\$appName.expand" -Recurse}

# Check the existence of the file "$importPath\$appName.msapp"
if (!(Test-Path "$importPath\$appName.msapp")) {
Write-Host "[HALT] $($MyInvocation.MyCommand.Name) Missing file:'$importPath\$appName.msapp' - Program stop with error $($MyInvocation.MyCommand.Name) " -ForegroundColor Red ;Sleep 3600;exit;}

# Unzip the compressed file
Copy-Item "$importPath\$appName.msapp" "$importPath\$appName.zip" -force
Expand-Archive -LiteralPath "$importPath\$appName.zip" -DestinationPath "$importPath\$appName.expand"

# Creation of the export folder
if (-not(test-path -path $exportPath)) {
New-Item $exportPath -type directory -force}

# Creation of the export CSV file
Get-ChildItem "$importPath\$appName.expand\Controls" -Name | ForEach-Object {
    $importFile = "$importPath\$appName.expand\Controls\$_"
    $json = (Get-Content $importfile -Raw) | ConvertFrom-Json
    $type = $json.TopParent | where { $_.Type -eq "ControlInfo" } 
    $rules = $type.Rules | Select-Object Property, InvariantScript
    $rules | ForEach-Object {
    $allObjects += [pscustomobject]@{
        AppScreen = $appName
        ScreenControl = $type.Name
        Property = $_.Property
        Value = $_.InvariantScript
        }
    $children = $type.Children | where { $_.Type -eq "ControlInfo" } 
    # Children of TopParent
    foreach ($child in $children) {
        $rules = $child.Rules | Select-Object Property, InvariantScript
        $rules | ForEach-Object {
        $allObjects += [pscustomobject]@{
            AppScreen = $type.Name
            ScreenControl = $child.Name
            Property = $_.Property
            Value = $_.InvariantScript
            }
        }
    }
}

$allObjects | Export-Csv -Path $exportfile -NoTypeInformation -Delimiter ";" -Encoding UTF8 -Append

# Open explorer
Invoke-Item $exportPath

In the CSV file, you will find properties that are not currently exposed by default in the Power Apps designer.

For example, the CalendarHeaderFill property of the Calendar control.

Calendar control CalendarHeaderFill RGBA(56, 96, 178, 1)
Calendar control CalendarHeaderFill RGBA(56, 96, 178, 1)

Microsoft365 Addict

Ajouter un commentaire