AWS VPNConnection using Powershell

0

I am trying to setup a new vpn connection with the AWS transit gateway using PowerShell. I need some assistance on how to setup tunnel options. AWS has very limited documentation with examples. Here is the link to the documentation. VPNTunnelSpecifications

Here is my script.

foreach ($v in $vpn) {
$name = $v.vpnname
$peer = $v.peerip
$psk = $v.psk
$type = 'ipsec.1'
$tgwid = 'tgw-07b5dbf2e29'
$agency = $v.Agency
$program = $v.Program
$poc = $v.poc

$ph1dh = @(14, 15, 16, 17, 18, 22, 23, 24)
$ph1ike = @("ikev2")
$ph1enc = @("AES256")
$ph1int = @("SHA2-256")
$ph2dh = @(14, 15, 16, 17, 18, 22, 23, 24)
$ph2enc = @("AES256")
$ph2int = @("SHA2-256")

$TunnelOptions = @( @{key = "dpdtimeoutseconds"; value = 30 }, `
    @{key = "IKEVersions"; value = $ph1ike }, `
    @{key = "Phase1DHGroupNumbers"; value = $ph1dh }, `
    @{key = "Phase1EncryptionAlgorithms"; value = $ph1enc }, `
    @{key = "Phase1IntegrityAlgorithms"; value = $ph1int }, `
    @{key = "Phase1LifetimeSeconds"; value = 28800 }, `
    @{key = "Phase2DHGroupNumbers"; value = $ph2dh }, `
    @{key = "Phase2EncryptionAlgorithms"; value = $ph2enc }, `
    @{key = "Phase2IntegrityAlgorithms"; value = $ph2int }, `
    @{key = "Phase2LifetimeSeconds"; value = 3600 }, `
    @{key = "PreSharedKey"; value = $psk }
)

##create customer gateway
$cg = New-EC2CustomerGateway -type $type -PublicIp $peer -DeviceName $name 
$cg
$cgid = $cg.CustomerGatewayId
$cgid

$vpngateway = New-EC2VpnConnection -CustomerGatewayId $cgid -TransitGatewayId $tgwid -Options_TunnelOption $TunnelOptions
$vpngateway
$VGWid = $vpngateway.VpnGatewayId
$VGWid

}

Here is error I have been getting.

$vpngateway = New-EC2VpnConnection -CustomerGatewayId $cgid -TransitGatewayId $tgwid -Options_TunnelOption $TunnelOptions
New-EC2VpnConnection : Cannot bind parameter 'Options_TunnelOption'. Cannot create object of type "Amazon.EC2.Model.VpnTunnelOptionsSpecification". The key property was not found for the Amazon.EC2.Model.VpnTunnelOptionsSpecification object. The available property is: [DPDTimeoutSeconds ] , [IKEVersions ] , [Phase1EncryptionAlgorithms ] , [Phase1LifetimeSeconds ] , [Phase2DHGroupNumbers ] , [Phase2IntegrityAlgorithms ] , [Phase2LifetimeSeconds ] , [PreSharedKey ] , [RekeyFuzzPercentage ] , [RekeyMarginTimeSeconds ] , [ReplayWindowSize ] , [TunnelInsideCidr ] At line:1 char:108 + ... d $cgid -TransitGatewayId $tgwid -Options_TunnelOption $TunnelOptions + ~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [New-EC2VpnConnection], ParameterBindingException + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Amazon.PowerShell.Cmdlets.EC2.NewEC2VpnConnectionCmdlet

Parvinder Raheja

Posted 2020-02-04T17:38:00.730

Reputation: 1

No answers