1

I am trying to use a PowerShell cmdlet to create a resource in Azure cloud:

$Gateway = New-AzApplicationGateway `
    -Name $GatewayName `
    -ResourceGroupName $ResourceGroupName `
    -Location $Location `
    -Sku $GatewaySku `
    -GatewayIPConfigurations $GatewayIPconfig `
    -FrontendIPConfigurations $FrontendIpConfig `
    -FrontendPorts $FrontEndPort `
    -Probes $HealthProbe `
    -BackendAddressPools $PlatformBackendPool, $ApiBackendPool `
    -BackendHttpSettingsCollection $PoolSettings `
    -Force

This, however, ends with:

cmdlet New-AzApplicationGateway at command pipeline position 1
Supply values for the following parameters:
(Type !? for Help.)
GatewayIPConfigurations[0]:

$GatewayIPconfig.GetType() yields

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     False    PSApplicationGatewayIPConfiguration      Microsoft.Azure.Commands.Network.Models.PSChildResource

and the documentation for the cmdlet states that the signature is

New-AzApplicationGateway
   ...
   -GatewayIPConfigurations <PSApplicationGatewayIPConfiguration[]>
   ...

Is this not the proper way to pass an array argument to a cmdlet?

1 Answer 1

2

It's just a guess, but do you maybe have a stray space or tab after -Sku $GatewaySku ' ? That might produce exactly the behavior you described. Basically that would be interpreted as:

$Gateway = New-AzApplicationGateway `
    -Name $GatewayName `
    -ResourceGroupName $ResourceGroupName `
    -Location $Location `
    -Sku $GatewaySku
# (the rest of the arguments will be missing)

It's a common pitfall when using the backtick that way. It is often recommended not to do it. It's because the backtick is not a continuation but an escape character, so anything after it will be escaped. When using it as you do, it's the line-break that is escaped, so you can put the arguments on separate lines, but if there's other whitespace in-between, this will break.

Best practice is to write everything in one line, or if there are too many arguments to keep it readable, you can use splatting:

$params = @{
    Name = $GatewayName
    ResourceGroupName = $ResourceGroupName
    Location = $Location
    Sku = $GatewaySku
    GatewayIPConfigurations = $GatewayIPconfig
    FrontendIPConfigurations = $FrontendIpConfig
    FrontendPorts = $FrontEndPort
    Probes = $HealthProbe
    BackendAddressPools = $PlatformBackendPool, $ApiBackendPool
    BackendHttpSettingsCollection = $PoolSettings
    Force = $true
}
$Gateway = New-AzApplicationGateway @params
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you @marsze, that was it! I was going crazy already. No more backticks from now on :)

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.