You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure PowerShell函数调用报错:Decrypt-Function未被识别

解决Azure PowerShell函数中Decrypt-Function未识别的问题
  • 确认自定义函数已正确定义并加载
    Azure PowerShell函数不会自动识别未定义的自定义函数,必须先在脚本中定义Decrypt-Function,再调用它。比如在run.ps1开头添加函数定义:

    function Decrypt-Function {
        param(
            [Parameter(Mandatory=$true)]
            [string]$Input,
            [Parameter(Mandatory=$true)]
            [string]$Key
        )
        # 替换为你的实际解密逻辑示例
        $encryptedBytes = [Convert]::FromBase64String($Input)
        $aes = [System.Security.Cryptography.Aes]::Create()
        $aes.Key = [Convert]::FromBase64String($Key)
        # 注意:实际场景中IV需与加密时一致,避免硬编码
        $aes.IV = $encryptedBytes[0..15]
        $decryptor = $aes.CreateDecryptor()
        $decryptedBytes = $decryptor.TransformFinalBlock($encryptedBytes, 16, $encryptedBytes.Length - 16)
        return [System.Text.Encoding]::UTF8.GetString($decryptedBytes)
    }
    

    如果函数定义在单独的脚本或模块中,要确保在调用前通过. .\DecryptScript.ps1(加载脚本)或Import-Module .\DecryptModule.psd1(加载模块)引入。

  • 检查函数名和参数拼写
    确认调用时的函数名Decrypt-Function与定义完全一致(PowerShell大小写不敏感,但需避免拼写错误),同时参数-Input和-Key要和函数定义中的参数名匹配,没有遗漏或错写。

  • 验证函数应用的运行环境

    • 确认函数应用的PowerShell Runtime版本(在Azure门户的函数应用配置中查看)支持你的代码语法,建议使用PowerShell 7.x版本。
    • 检查文件结构:自定义脚本或模块需放置在函数应用的site/wwwroot目录下(或对应函数子目录),确保部署时已上传所有依赖文件。
  • 添加调试日志定位问题
    在调用Decrypt-Function前添加日志输出,确认函数是否已加载:

    Write-Host "Available commands: $(Get-Command -Name Decrypt-Function -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Name)"
    

    通过Azure门户的日志流查看输出,判断函数是否被正确识别。

内容的提问来源于stack exchange,提问作者Maheswata

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.03 06:17:08