Trying to remove AIP sensitivity labels from PDF documents using PowerShell Azure Function (triggered by power automate flow passing the file content from SharePoint).
Based on this documentation: https://learn.microsoft.com/en-us/azure/information-protection/rms-client/clientv2-admin-guide-powershell
I've imported the PowerShell module manually (testing the below snippet on windows without the unified client installed works fine..)
When trying to do the same from the Azure powershell I'm getting:
Engine is not initialized, bootstrap might have failedHResult : -2146233087CategoryInfo : InvalidOperation: (:) [Set-AIPFileLabel], InvalidOperationExceptionFullyQualifiedErrorId : Microsoft.InformationProtection.Powershell.AIP.Commandlets.SetAIPFileLabelCmdLetException: Engine is not initialized, bootstrap might have failedStack:
run.ps1:
using namespace System.Net
# Input bindings are passed in via param block.
param($Request, $TriggerMetadata)
Import-Module "C:\home\site\wwwroot\Modules\Microsoft Azure Information Protection\Powershell\AzureInformationProtection\AzureInformationProtection.psd1" -UseWindowsPowerShell
##Credentials##
$TenantId = $ENV:TenantId
$ApplicationId = $ENV:ApplicationId
$SecretValue = $ENV:ApplicationSecret
$DelegatedUser = $ENV:DelegatedUser
Set-AIPAuthentication -AppId $ApplicationId -AppSecret $SecretValue -TenantId $TenantId -DelegatedUser $DelegatedUser
Set-AIPFileLabel "C:\home\data\Temp\test.pdf" -RemoveProtection -RemoveLabel -JustificationMessage "Need it decrypted"
# Associate values to output bindings by calling 'Push-OutputBinding'.
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
StatusCode = [HttpStatusCode]::OK
Body = "TEST"
})