Aure Function Powershell Error Hashtable on get-content

Nicolas Schroeders 21 Reputation points
2021-03-30T07:20:54.35+00:00

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
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,911 questions
{count} votes

Accepted answer
  1. Dmytro Vasyutin 76 Reputation points
    2021-04-01T13:36:10.307+00:00

    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


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.