azure-functionspowershell-7.2

The term 'Invoke-AzSynapsePipeline' is not recognized as a name of a cmdlet, function, script file, or executable program


I'm using a Azure Function with the following powershell script

using namespace System.Net

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

# Write to the Azure Functions log stream.
Write-Host "PowerShell HTTP trigger function processed a request."

# Interact with query parameters or the body of the request.
$WorkspaceName = $Request.Query.WorkspaceName
if (-not $WorkspaceName) {
    $WorkspaceName = $Request.Body.WorkspaceName
}
$PipelineName = $Request.Query.PipelineName
if (-not $PipelineName) {
    $PipelineName = $Request.Body.PipelineName
}

$body = "Random text"

# if ($name) {
#     $body = "Hello, $name. This HTTP triggered function executed successfully."
# }

Invoke-AzSynapsePipeline -WorkspaceName $WorkspaceName -PipelineName $PipelineName 

# Associate values to output bindings by calling 'Push-OutputBinding'.
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
    StatusCode = [HttpStatusCode]::OK
    Body = $body
})

And i'm getting the following error:

Message : The term 'Invoke-AzSynapsePipeline' is not recognized as a name of a cmdlet, function, script file, or executable program.
                      Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

I've already went to app_files in the function app and uncomment the the following line in the requirements.psd1 and its like that:

# This file enables modules to be automatically managed by the Functions service.
# See https://aka.ms/functionsmanageddependency for additional information.
#
@{
    # For latest supported version, go to 'https://www.powershellgallery.com/packages/Az'. 
    # To use the Az module in your function app, please uncomment the line below.
     'Az' = '9.*'
}

How can i make Azure read correctly the Invoke-AzSynapsePipeline command? Also i'm using powershell 7.2 in the function App


Solution

  • I have created Azure Functions PowerShell Language - Basic Http Trigger and modified the code according to your requirement and working as expected.

    run.ps1:

    using  namespace  System.Net
    
    # Input bindings are passed in via param block.
    param($Request, $TriggerMetadata)
    
    # Write to the Azure Functions log stream.
    Write-Host  "PowerShell HTTP trigger function processed a request."
    
    $WorkspaceName = $Request.Query.WorkspaceName
    if (-not $WorkspaceName) {
    $WorkspaceName = $Request.Body.WorkspaceName
    }
    
    $PipelineName = $Request.Query.PipelineName
    if (-not $PipelineName) {
    $PipelineName = $Request.Body.PipelineName
    }  
    
    $body = "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response."
    
    if ($WorkspaceName && $PipelineName) {
    $body = "Hello Krishna, This HTTP triggered function executed successfully."
    }
    
    Invoke-AzSynapsePipeline -WorkspaceName $WorkspaceName -PipelineName $PipelineName
    
    Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
    StatusCode = [HttpStatusCode]::OK
    Body = $body
    
    })
    

    requirements.psd1:

    @{
    'Az' = '9.*'
    'Az.Synapse' = '0.10.0'
    }
    

    Result: enter image description here

    Note: Part of the above code taken from the MS Doc 1 & 2 references.