Hi Team,
I have a cosmos DB table in which I have created few entities. I need to read these entitiy values in Azure Powershell function.
So, I have created a cosmos DB trigger function which created a sample function with the code as below which will print latest modified entity.
param($Documents, $TriggerMetadata)
if ($Documents.Count -gt 0) {
Write-Host "Document Id: $($Documents[0].id)"
}
My requirement is to fetch the values from existing entities. If I give Write-Host "$Documents[0].accountEmail" to fetch the value of accountEmail from cosmos table I didnt get any value. Instead it returned null value.
Earlier we are able to access the envType by using $Documents[0].envType for cosmos DB SQL trigger But now facing issue with cosmos DB which is nosql.
SO, I tried alternate approach by importing module with the below commands.
Import-Module AzTable
Import-Module Az.Storage
$cloudTable = "my-table"
Get-AzTableRow -table $cloudTable | ft
I got below error. Not sure how to access cosmos db table entities from azure funtion.
Also, I am unable to perform any operation like New-AzManagementGroup -GroupName 'Contoso' mentioned in the link after installing all the modules. Please guide us how to fix this and can use powershell commands in Azure function.
2021-09-06T06:08:37.204 [Error] ERROR: Method invocation failed because [System.String] does not contain a method named 'ExecuteQuerySegmentedAsync'.Exception :Type : System.Management.Automation.RuntimeExceptionErrorRecord :Exception :Type : System.Management.Automation.ParentContainsErrorRecordExceptionMessage : Method invocation failed because [System.String] does not contain a method named 'ExecuteQuerySegmentedAsync'.HResult : -2146233087CategoryInfo : InvalidOperation: (:) [], ParentContainsErrorRecordExceptionFullyQualifiedErrorId : MethodNotFoundInvocationInfo :ScriptLineNumber : 56OffsetInLine : 4HistoryId : -1ScriptName : C:\home\data\ManagedDependencies\210906060508926.r\AzTable\2.1.0\AzureRmStorageTableCoreHelper.psm1Line : $Results = $Table.ExecuteQuerySegmentedAsync($TableQuery, $token)PositionMessage : At C:\home\data\ManagedDependencies\210906060508926.r\AzTable\2.1.0\AzureRmStorageTableCoreHelper.psm1:56 char:4+ $Results = $Table.ExecuteQuerySegmentedAsync($TableQuery, …+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~PSScriptRoot : C:\home\data\ManagedDependencies\210906060508926.r\AzTable\2.1.0PSCommandPath : C:\home\data\ManagedDependencies\210906060508926.r\AzTable\2.1.0\AzureRmStorageTableCoreHelper.psm1CommandOrigin : InternalScriptStackTrace : at ExecuteQueryAsync, C:\home\data\ManagedDependencies\210906060508926.r\AzTable\2.1.0\AzureRmStorageTableCoreHelper.psm1: line 56at Get-AzTableRow, C:\home\data\ManagedDependencies\210906060508926.r\AzTable\2.1.0\AzureRmStorageTableCoreHelper.psm1: line 683at <ScriptBlock>, C:\home\site\wwwroot\CosmosTrigger1\run.ps1: line 10TargetSite : System.Object CallSite.Target(System.Runtime.CompilerServices.Closure, System.Runtime.CompilerServices.CallSite, System.Object, System.Object, System.Object)StackTrace :at CallSite.Target(Closure , CallSite , Object , Object , Object )at System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2)at System.Management.Automation.Interpreter.DynamicInstruction`4.Run(InterpretedFrame frame)at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)Message : Method invocation failed because [System.String] does not contain a method named 'ExecuteQuerySegmentedAsync'.Data