public override void Execute()
{
base.Execute();
// Verify if the subnet exists in the VirtualNetwork
var peering = this.ExpressRouteCircuit.Peerings.SingleOrDefault(resource => string.Equals(resource.Name, this.Name, System.StringComparison.CurrentCultureIgnoreCase));
if (peering != null)
{
throw new ArgumentException("Peering with the specified name already exists");
}
peering = new PSPeering();
peering.Name = this.Name;
peering.PeeringType = this.PeeringType;
peering.PrimaryPeerAddressPrefix = this.PrimaryPeerAddressPrefix;
peering.SecondaryPeerAddressPrefix = this.SecondaryPeerAddressPrefix;
peering.PeerASN = this.PeerASN;
peering.VlanId = this.VlanId;
if (!string.IsNullOrEmpty(this.SharedKey))
{
peering.SharedKey = this.SharedKey;
}
if (this.MicrosoftConfigAdvertisedPublicPrefixes != null
&& this.MicrosoftConfigAdvertisedPublicPrefixes.Any())
{
peering.MicrosoftPeeringConfig = new PSPeeringConfig();
peering.MicrosoftPeeringConfig.AdvertisedPublicPrefixes = this.MicrosoftConfigAdvertisedPublicPrefixes;
peering.MicrosoftPeeringConfig.CustomerASN = this.MicrosoftConfigCustomerAsn;
peering.MicrosoftPeeringConfig.RoutingRegistryName = this.MicrosoftConfigRoutingRegistryName;
}
this.ExpressRouteCircuit.Peerings.Add(peering);
WriteObject(this.ExpressRouteCircuit);
}
}