Powershell强制参数,我是Powershell脚本的新手

Powershell强制参数,我是Powershell脚本的新手,powershell,Powershell,我的ci/cd上有一个任务,它在powershell脚本下调用,意味着在同一作业上的其他部署任务之前停止一个函数。即使我已正确设置了所有变量,脚本似乎仍会抛出错误。请帮忙,并提前表示感谢 #####Script####### Param( [Parameter(Mandatory)][string] $XxxxFunctionAppName, [Parameter(Mandatory)][string] $ResourceGroupName ) #stoping function

我的ci/cd上有一个任务,它在powershell脚本下调用,意味着在同一作业上的其他部署任务之前停止一个函数。即使我已正确设置了所有变量,脚本似乎仍会抛出错误。请帮忙,并提前表示感谢

#####Script#######
Param(
    [Parameter(Mandatory)][string] $XxxxFunctionAppName,
    [Parameter(Mandatory)][string] $ResourceGroupName
)
#stoping function app
$trap = Get-AzFunctionApp -Name $XxxxFunctionAppName -ResourceGroupName $ResourceGroupName -ErrorAction SilentlyContinue
if($trap.state -eq "Running")
{
Stop-AzFunctionApp -Force
}

####Error message#####
2021-04-06T10:24:43.3332161Z ## Validating Inputs
2021-04-06T10:24:43.3390381Z ## Validating Inputs Complete
2021-04-06T10:24:43.4262841Z ## Initializing Az module
2021-04-06T10:24:43.6949853Z Added TLS 1.2 in session.
2021-04-06T10:24:44.0148107Z ##[command]Import-Module -Name C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\1.9.0\Az.Accounts.psd1 -Global
2021-04-06T10:24:44.9908767Z ##[command]Clear-AzContext -Scope CurrentUser -Force -ErrorAction SilentlyContinue
2021-04-06T10:24:45.5333784Z ##[command]Clear-AzContext -Scope Process
2021-04-06T10:24:45.9446194Z ##[command]Connect-AzAccount -ServicePrincipal -Tenant *** -Credential System.Management.Automation.PSCredential -Environment AzureCloud @processScope
2021-04-06T10:24:46.9272395Z ##[command] Set-AzContext -SubscriptionId XXXXXXXXXXXXXXX -TenantId ***
2021-04-06T10:24:47.4342523Z ## Az module initialization Complete
2021-04-06T10:24:47.4352242Z ## Beginning Script Execution
2021-04-06T10:24:47.4690205Z ##[command]& 'c:\vstsagent\A4\_work\r241\a\_xxxxxxxxxxxx\Scripts\Stopxxxx.ps1' -xxxxFunctionAppName "func-xxxxx-develop-02" -ResourceGroupName "xxxxx-develop-rg"
2021-04-06T10:24:50.7841003Z ##[command]Disconnect-AzAccount -Scope Process -ErrorAction Stop
2021-04-06T10:24:51.2391709Z ##[command]Clear-AzContext -Scope Process -ErrorAction Stop
2021-04-06T10:24:51.8052164Z ##[error]Cannot process command because of one or more missing mandatory parameters: Name ResourceGroupName.
2021-04-06T10:24:51.8527691Z ##[section]Finishing: StopxxxxFunc

你怎么称呼这个脚本?(在调用它时,不要在参数之间使用括号和逗号)这就是我如何将其命名为$(System.DefaultWorkingDirectory)/_Xxxx-Infrastructure/Scripts/StopXxxxFunc.ps1,然后将脚本参数添加为-xxxxxxFunctionAppName“$(xxxxxxFunctionAppName)”-ResourceGroupName“$(ResourceGroupName)”
ResourceGroupName
是函数还是变量?如果它是一个变量,它应该是:
$ResourceGroupName
,如果它是一个函数,请确保已填充它。它是一个类似于脚本上的-ResourceGroupName$ResourceGroupName的变量。您需要向它传递一个实际值,而不是为参数创建的变量:
-xxxxfunctionppname“MyFunction AppName”-ResourceGroupName“resourceGrouptesta”