Az PowerShell Function - HTTP 204 No Content

PS 401 Reputation points
2023-03-14T11:10:55.56+00:00

Hi All, I need some insight on how to troubleshoot this scenario.

I am trying to access the VM using the Az PowerShell Function hosted on the same vnet and this is just a test only. my objective is to access the Windows AD after successfully connecting to VM.

My code looks like below:

param($Request, $TriggerMetadata)

$HybridEndpoint = $Env:HybridEndpoint

$Script = {
    Param(
        [Parameter(Mandatory=$True)]
        [String] $Service
    )
    Get-Service *
     #Get-AdUser -Identity $Env:SampleSID
}

Write-Output "Scenario 1: Running command via Invoke-Command"
Invoke-AzVMRunCommand -ComputerName $HybridEndpoint `
               -Scriptstring $Script 

When I run the function with the following input

{
  "name": "Azure"
}

I am not getting HTTP 204 No Content with an empty body.

Can someone please provide more insight on where the issue is or a way to troubleshoot.

Thank you!

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,909 questions
Windows for business Windows Server User experience PowerShell
{count} votes

1 answer

Sort by: Most helpful
  1. MayankBargali-MSFT 70,936 Reputation points Moderator
    2023-03-15T06:00:47.09+00:00

    @PS Thanks for reaching out. Can you please confirm if you are running the powershell script in Azure function? In case if it is Azure function then you need to leverage Push-OutputBinding as documented here.

    
    $out = Invoke-AzVMRunCommand -ComputerName $HybridEndpoint `
                   -Scriptstring $Script 
    Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
        StatusCode = [System.Net.HttpStatusCode]::OK
        Body = "$out"
    })
    
    
    {
      "bindings": [
        {
          "type": "httpTrigger",
          "direction": "in",
          "authLevel": "anonymous"
        },
        {
          "type": "http",
          "direction": "out",
          "name": "Response"
        }
      ]
    }
    

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.