question

85925869 avatar image
0 Votes"
85925869 asked 85925869 commented

Aure Function Powershell Error Hashtable on get-content

Hello,
I have deployed a Powershell Azure Function running Powershell Core 7.0.
I integrate the function with a Storage Queue.
My message queue is a String:

{

"WebTemplate": "STS#0",
"SiteTitle": "TestCreation1",
"SiteURL": "TestCreation1",
"SiteLanguage": 1033
}

When adding the message in the queue, the function triggers it but I have an error in the function logs.
My function code ( run.ps - The write host are just for troubleshooting):

using namespace System.Net

# Input bindings are passed in via param block.
param($QueueItem, $TriggerMetadata)


# Write out the queue message and insertion time to the information logs.
Write-Host "PowerShell queue trigger function processed work item **: $QueueItem"
Write-Host "Queue item insertion time: $($TriggerMetadata.InsertionTime)"

Write-Host "requestBody Get-Content $QueueItem -Raw | ConvertFrom-Json"
$requestBody = Get-Content $QueueItem -Raw | ConvertFrom-Json


$WebTemplate = $requestBody.WebTemplate
Write-Host "WebTemplate: $WebTemplate"



$SiteTitle = $requestBody.SiteTitle
Write-Host "SiteTitle: $SiteTitle"


$SiteURL = $requestBody.SiteURL
Write-Host "SiteURL: $SiteURL"

$SiteLanguage = $requestBody.SiteLanguage
Write-Host "SiteLanguage: $SiteLanguage"


$SiteDescription = "Site with PowerShell"
Write-Host "SiteDescription: $SiteDescription"


Write-Output "PowerShell script processed queue message '$requestBody'"

My issue:
During the execution of
$requestBody = Get-Content $QueueItem -Raw | ConvertFrom-Json
I have an error saying the the System.Collections.Hastable does not exist.

ERROR: Cannot find path 'C:\home\site\wwwroot\System.Collections.Hashtable' because it does not exist.

Anyone, any ideas from what it can come from?
Thanks in advance




azure-functions
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@NicolasSchroeders-2820 Thanks for reaching out. I am looking into it and will share my observation.

1 Vote 1 ·

1 Answer

DmytroVasyutin-1348 avatar image
0 Votes"
DmytroVasyutin-1348 answered 85925869 commented

Hi @NicholasSchroeders-2820

It started working for me like this:

function code:

param([object]$QueueItem, $TriggerMetadata)


Write-Host "PowerShell queue trigger function processed work item: $SiteURL"
Write-Host "Queue item insertion time: $($TriggerMetadata.InsertionTime)"


$SiteURL = $QueueItem.SiteURL
$SCA2 = $QueueItem.SCA2

$Siteowner= $QueueItem.SiteOwner
$Sharing = $QueueItem.Sharing
$Template = $QueueItem.Template

Write-Output "'$SiteURL'"
Write-Output "'$SCA2'"
Write-Output "'$Siteowner'"
Write-Output "'$Sharing'"
Write-Output "'$Template'"


json input:

{
"SiteURL": "https://<tenancy>.sharepoint.com/sites/DemoGroupCommittee312",
"SCA2": "<USER UPN>",
"Siteowner": "User UPN",
"Sharing": "Yes",
"Template": "Committee Meeting site"
}

I don't know if I'm doing it right, but this one works (in tests).

HTH,
Dmytro

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks Dmytro for the solution, it's highly appreciated. It took some time as I was out-of-office.
It's the [object] that was missing in the param. Then the Get-content is not needed anymore.

Thanks,
Nicolas

0 Votes 0 ·