0

I'm trying to do a deployment using powershell. Both parameter and template file are stored in blob storage, but I get the error below before it even tries to download the blobs.

New-AzResourceGroupDeployment : A positional parameter cannot be found that accepts argument 'newdeployment-878059'. At C:\Temp\New-Deployment\deploy-core.ps1:86 char:1

The code I use is below

$vnetRG = "rg-vnet"
$vpnRG = "rg-vpn"
$fwRG = "rg-fw"
$btnRG = "rg-bastion"
$loc = "west europe"

New-AzResourceGroupDeployment -Name = "newdeployment-$random"-ResourceGroupName "rg-vnet" `
  -TemplateParameterFile "$PSScriptRoot\core.parameters.json" -TemplateUri = $templateFileUri `
  -vpnResourceGroupName $rgRG -vpnResourceGroupName $vpnRG -fwResourceGroupName $fwRG  -btnResourceGroupName $btnRG 

I'm trying to deploy multiple resources to various resource groups in one subscription.

Thanks in advance :)

2
  • 2
    Remove the = after the parameter name. Also, looking at the docs, I don't see parameters vpnResourceGroupName, fwResourceGroupName or btnResourceGroupName on that cmdlet. Not only that, but you have added vpnResourceGroupName twice.. And if I may suggest, have a look at Splatting parameters for cmdlets that can take a lot of parameters. Commented Sep 16, 2020 at 11:20
  • Thanks @Theo cannot believe I did that. Thanks for your help and I was using splatting but spread everything out trying to isolate the issue. Thanks again. Could you mark your reply as an aswer and I'll accept :) Commented Sep 16, 2020 at 13:59

1 Answer 1

1

Here my comment as answer

In your code, you have added an = character between some of the parameter names and the actual value to use for that parameter.
In PowerShell you assign a value to a parameter with a space character between the two.

Also, there are parameters used that (according to the docs) don't exist for that cmdlet, like vpnResourceGroupName, fwResourceGroupName and btnResourceGroupName. To me, they sound like variables mistakenly added as parameter with the leading $ stripped off?

For cmdlets that can potentially use a large number of parameters, I'd recommend using Splatting, to keep the code clean and easy to maintain.

Something like:

$splatParams = @{
    Name                  = "newdeployment-$random"
    ResourceGroupName     = "rg-vnet"
    TemplateParameterFile = "$PSScriptRoot\core.parameters.json"
    TemplateUri           = $templateFileUri
}

New-AzResourceGroupDeployment @splatParams
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.