protected override void ProcessRecord()
        {
            base.ProcessRecord();

            if (!this.IsLoadBalancerPresent(this.LoadBalancer.ResourceGroupName, this.LoadBalancer.Name))
            {
                throw new ArgumentException(Microsoft.Azure.Commands.Network.Properties.Resources.ResourceNotFound);
            }

            // Normalize the IDs
            ChildResourceHelper.NormalizeChildResourcesId(this.LoadBalancer);

            // Map to the sdk object
            var lbModel = Mapper.Map <MNM.LoadBalancer>(this.LoadBalancer);

            lbModel.Type = Microsoft.Azure.Commands.Network.Properties.Resources.LoadBalancerType;
            lbModel.Tags = TagsConversionHelper.CreateTagDictionary(this.LoadBalancer.Tag, validate: true);

            // Execute the Create VirtualNetwork call
            this.LoadBalancerClient.CreateOrUpdate(this.LoadBalancer.ResourceGroupName, this.LoadBalancer.Name, lbModel);

            var getLoadBalancer = this.GetLoadBalancer(this.LoadBalancer.ResourceGroupName, this.LoadBalancer.Name);

            WriteObject(getLoadBalancer);
        }
Пример #2
0
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            var existingbackendAddressPool = this.LoadBalancer.BackendAddressPools.SingleOrDefault(resource => string.Equals(resource.Name, this.Name, System.StringComparison.CurrentCultureIgnoreCase));

            if (existingbackendAddressPool != null)
            {
                throw new ArgumentException("BackendAddressPool with the specified name already exists");
            }

            var backendAddressPool = new PSBackendAddressPool();

            backendAddressPool.Name = this.Name;

            backendAddressPool.Id =
                ChildResourceHelper.GetResourceId(
                    this.NetworkClient.NetworkManagementClient.SubscriptionId,
                    this.LoadBalancer.ResourceGroupName,
                    this.LoadBalancer.Name,
                    Microsoft.Azure.Commands.Network.Properties.Resources.LoadBalancerBackendAddressPoolName,
                    this.Name);

            this.LoadBalancer.BackendAddressPools.Add(backendAddressPool);

            WriteObject(this.LoadBalancer);
        }
        protected override void ProcessRecord()
        {
            base.ProcessRecord();

            var inboundNatPool = new PSInboundNatPool();

            inboundNatPool.Name     = this.Name;
            inboundNatPool.Protocol = this.Protocol;
            inboundNatPool.FrontendPortRangeStart = this.FrontendPortRangeStart;
            inboundNatPool.FrontendPortRangeEnd   = this.FrontendPortRangeEnd;
            inboundNatPool.BackendPort            = this.BackendPort;

            if (!string.IsNullOrEmpty(this.FrontendIpConfigurationId))
            {
                inboundNatPool.FrontendIPConfiguration = new PSResourceId()
                {
                    Id = this.FrontendIpConfigurationId
                };
            }

            inboundNatPool.Id =
                ChildResourceHelper.GetResourceNotSetId(
                    this.NetworkClient.NetworkResourceProviderClient.Credentials.SubscriptionId,
                    Microsoft.Azure.Commands.Network.Properties.Resources.LoadBalancerInboundNatPoolsName,
                    this.Name);

            WriteObject(inboundNatPool);
        }
Пример #4
0
        public override void Execute()
        {
            base.Execute();

            var inboundNatRule = new PSInboundNatRule();

            inboundNatRule.Name         = this.Name;
            inboundNatRule.Protocol     = this.Protocol;
            inboundNatRule.FrontendPort = this.FrontendPort;
            inboundNatRule.BackendPort  = this.BackendPort;
            if (this.IdleTimeoutInMinutes > 0)
            {
                inboundNatRule.IdleTimeoutInMinutes = this.IdleTimeoutInMinutes;
            }
            inboundNatRule.EnableFloatingIP = this.EnableFloatingIP.IsPresent;

            if (!string.IsNullOrEmpty(this.FrontendIpConfigurationId))
            {
                inboundNatRule.FrontendIPConfiguration = new PSResourceId()
                {
                    Id = this.FrontendIpConfigurationId
                };
            }

            inboundNatRule.Id =
                ChildResourceHelper.GetResourceNotSetId(
                    this.NetworkClient.NetworkManagementClient.SubscriptionId,
                    Microsoft.Azure.Commands.Network.Properties.Resources.LoadBalancerInBoundNatRuleName,
                    this.Name);

            WriteObject(inboundNatRule);
        }
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            var existingProbe = this.LoadBalancer.Probes.SingleOrDefault(resource => string.Equals(resource.Name, this.Name, System.StringComparison.CurrentCultureIgnoreCase));

            if (existingProbe != null)
            {
                throw new ArgumentException("Probe with the specified name already exists");
            }

            var probe = new PSProbe();

            probe.Name              = this.Name;
            probe.Port              = this.Port;
            probe.Protocol          = this.Protocol;
            probe.RequestPath       = this.RequestPath;
            probe.IntervalInSeconds = this.IntervalInSeconds;
            probe.NumberOfProbes    = this.ProbeCount;

            probe.Id =
                ChildResourceHelper.GetResourceId(
                    this.NetworkClient.NetworkManagementClient.SubscriptionId,
                    this.LoadBalancer.ResourceGroupName,
                    this.LoadBalancer.Name,
                    Microsoft.Azure.Commands.Network.Properties.Resources.LoadBalancerProbeName,
                    this.Name);

            this.LoadBalancer.Probes.Add(probe);

            WriteObject(this.LoadBalancer);
        }
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            var frontendPort = this.ApplicationGateway.FrontendPorts.SingleOrDefault(resource => string.Equals(resource.Name, this.Name, System.StringComparison.CurrentCultureIgnoreCase));

            if (frontendPort != null)
            {
                throw new ArgumentException("Frontend port with the specified name already exists");
            }

            frontendPort      = new PSApplicationGatewayFrontendPort();
            frontendPort.Name = this.Name;
            frontendPort.Port = this.Port;

            frontendPort.Id =
                ChildResourceHelper.GetResourceId(
                    this.NetworkClient.NetworkResourceProviderClient.Credentials.SubscriptionId,
                    this.ApplicationGateway.ResourceGroupName,
                    this.ApplicationGateway.Name,
                    Microsoft.Azure.Commands.Network.Properties.Resources.ApplicationGatewayFrontendPortName,
                    this.Name);

            this.ApplicationGateway.FrontendPorts.Add(frontendPort);

            WriteObject(this.ApplicationGateway);
        }
Пример #7
0
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            var inboundNatPool = new PSInboundNatPool();

            inboundNatPool.Name     = this.Name;
            inboundNatPool.Protocol = this.Protocol;
            inboundNatPool.FrontendPortRangeStart = this.FrontendPortRangeStart;
            inboundNatPool.FrontendPortRangeEnd   = this.FrontendPortRangeEnd;
            inboundNatPool.BackendPort            = this.BackendPort;

            if (!string.IsNullOrEmpty(this.FrontendIpConfigurationId))
            {
                inboundNatPool.FrontendIPConfiguration = new PSResourceId()
                {
                    Id = this.FrontendIpConfigurationId
                };
            }

            inboundNatPool.Id =
                ChildResourceHelper.GetResourceNotSetId(
                    this.NetworkClient.NetworkManagementClient.SubscriptionId,
                    Microsoft.Azure.Commands.Network.Properties.Resources.LoadBalancerInboundNatPoolName,
                    this.Name);

            WriteObject(inboundNatPool);
        }
Пример #8
0
        private PSLoadBalancer CreateLoadBalancer()
        {
            var loadBalancer = new PSLoadBalancer();

            loadBalancer.Name = this.Name;
            loadBalancer.ResourceGroupName = this.ResourceGroupName;
            loadBalancer.Location          = this.Location;

            if (this.FrontendIpConfiguration != null)
            {
                loadBalancer.FrontendIpConfigurations = new List <PSFrontendIPConfiguration>();
                loadBalancer.FrontendIpConfigurations = this.FrontendIpConfiguration;
            }

            if (this.BackendAddressPool != null)
            {
                loadBalancer.BackendAddressPools = new List <PSBackendAddressPool>();
                loadBalancer.BackendAddressPools = this.BackendAddressPool;
            }

            if (this.Probe != null)
            {
                loadBalancer.Probes = new List <PSProbe>();
                loadBalancer.Probes = this.Probe;
            }

            if (this.InboundNatRule != null)
            {
                loadBalancer.InboundNatRules = new List <PSInboundNatRule>();
                loadBalancer.InboundNatRules = this.InboundNatRule;
            }

            if (this.LoadBalancingRule != null)
            {
                loadBalancer.LoadBalancingRules = new List <PSLoadBalancingRule>();
                loadBalancer.LoadBalancingRules = this.LoadBalancingRule;
            }

            if (this.InboundNatPool != null)
            {
                loadBalancer.InboundNatPools = new List <PSInboundNatPool>();
                loadBalancer.InboundNatPools = this.InboundNatPool;
            }

            // Normalize the IDs
            ChildResourceHelper.NormalizeChildResourcesId(loadBalancer);

            // Map to the sdk object
            var lbModel = Mapper.Map <MNM.LoadBalancer>(loadBalancer);

            lbModel.Type = Microsoft.Azure.Commands.Network.Properties.Resources.LoadBalancerType;
            lbModel.Tags = TagsConversionHelper.CreateTagDictionary(this.Tag, validate: true);

            // Execute the Create VirtualNetwork call
            this.LoadBalancerClient.CreateOrUpdate(this.ResourceGroupName, this.Name, lbModel);

            var getLoadBalancer = this.GetLoadBalancer(this.ResourceGroupName, this.Name);

            return(getLoadBalancer);
        }
        private PSLoadBalancer CreateLoadBalancer()
        {
            var loadBalancer = new PSLoadBalancer();

            loadBalancer.Name = this.Name;
            loadBalancer.ResourceGroupName = this.ResourceGroupName;
            loadBalancer.Location          = this.Location;

            if (this.FrontendIpConfiguration != null)
            {
                loadBalancer.FrontendIpConfigurations = this.FrontendIpConfiguration;
            }

            if (this.BackendAddressPool != null)
            {
                loadBalancer.BackendAddressPools = this.BackendAddressPool;
            }

            if (this.Probe != null)
            {
                loadBalancer.Probes = this.Probe;
            }

            if (this.InboundNatRule != null)
            {
                loadBalancer.InboundNatRules = this.InboundNatRule;
            }

            if (this.LoadBalancingRule != null)
            {
                loadBalancer.LoadBalancingRules = this.LoadBalancingRule;
            }

            if (this.InboundNatPool != null)
            {
                loadBalancer.InboundNatPools = this.InboundNatPool;
            }

            loadBalancer.ResourceGroupName = this.ResourceGroupName;
            loadBalancer.Name = this.Name;

            // Normalize the IDs
            ChildResourceHelper.NormalizeChildResourcesId(loadBalancer, this.NetworkClient.NetworkManagementClient.SubscriptionId);

            // Map to the sdk object
            var lbModel = Mapper.Map <MNM.LoadBalancer>(loadBalancer);

            lbModel.Tags = TagsConversionHelper.CreateTagDictionary(this.Tag, validate: true);

            // Execute the Create VirtualNetwork call
            this.LoadBalancerClient.CreateOrUpdate(this.ResourceGroupName, this.Name, lbModel);

            var getLoadBalancer = this.GetLoadBalancer(this.ResourceGroupName, this.Name);

            return(getLoadBalancer);
        }
Пример #10
0
        public override void Execute()
        {
            base.Execute();

            var existingFrontendIpConfig = this.LoadBalancer.FrontendIpConfigurations.SingleOrDefault(resource => string.Equals(resource.Name, this.Name, System.StringComparison.CurrentCultureIgnoreCase));

            if (existingFrontendIpConfig != null)
            {
                throw new ArgumentException("FrontendIpConfiguration with the specified name already exists");
            }

            var frontendIpConfig = new PSFrontendIPConfiguration();

            frontendIpConfig.Name  = this.Name;
            frontendIpConfig.Zones = this.Zone;

            if (!string.IsNullOrEmpty(this.SubnetId))
            {
                frontendIpConfig.Subnet    = new PSSubnet();
                frontendIpConfig.Subnet.Id = this.SubnetId;

                if (!string.IsNullOrEmpty(this.PrivateIpAddress))
                {
                    frontendIpConfig.PrivateIpAddress          = this.PrivateIpAddress;
                    frontendIpConfig.PrivateIpAllocationMethod = Management.Network.Models.IPAllocationMethod.Static;
                }
                else
                {
                    frontendIpConfig.PrivateIpAllocationMethod = Management.Network.Models.IPAllocationMethod.Dynamic;
                }
            }

            if (!string.IsNullOrEmpty(this.PublicIpAddressId))
            {
                frontendIpConfig.PublicIpAddress    = new PSPublicIpAddress();
                frontendIpConfig.PublicIpAddress.Id = this.PublicIpAddressId;
            }

            frontendIpConfig.Id =
                ChildResourceHelper.GetResourceId(
                    this.NetworkClient.NetworkManagementClient.SubscriptionId,
                    this.LoadBalancer.ResourceGroupName,
                    this.LoadBalancer.Name,
                    Microsoft.Azure.Commands.Network.Properties.Resources.LoadBalancerFrontendIpConfigName,
                    this.Name);

            this.LoadBalancer.FrontendIpConfigurations.Add(frontendIpConfig);

            WriteObject(this.LoadBalancer);
        }
        protected override void ProcessRecord()
        {
            base.ProcessRecord();

            var loadBalancingRule = new PSLoadBalancingRule();

            loadBalancingRule.Name         = this.Name;
            loadBalancingRule.Protocol     = this.Protocol;
            loadBalancingRule.FrontendPort = this.FrontendPort;
            loadBalancingRule.BackendPort  = this.BackendPort;
            if (this.IdleTimeoutInMinutes > 0)
            {
                loadBalancingRule.IdleTimeoutInMinutes = this.IdleTimeoutInMinutes;
            }

            if (!string.IsNullOrEmpty(this.LoadDistribution))
            {
                loadBalancingRule.LoadDistribution = this.LoadDistribution;
            }

            loadBalancingRule.EnableFloatingIP = this.EnableFloatingIP.IsPresent;

            if (!string.IsNullOrEmpty(this.BackendAddressPoolId))
            {
                loadBalancingRule.BackendAddressPool    = new PSResourceId();
                loadBalancingRule.BackendAddressPool.Id = this.BackendAddressPoolId;
            }

            if (!string.IsNullOrEmpty(this.ProbeId))
            {
                loadBalancingRule.Probe    = new PSResourceId();
                loadBalancingRule.Probe.Id = this.ProbeId;
            }

            if (!string.IsNullOrEmpty(this.FrontendIpConfigurationId))
            {
                loadBalancingRule.FrontendIPConfiguration = new PSResourceId()
                {
                    Id = this.FrontendIpConfigurationId
                };
            }

            loadBalancingRule.Id =
                ChildResourceHelper.GetResourceNotSetId(
                    this.NetworkClient.NetworkResourceProviderClient.Credentials.SubscriptionId,
                    Microsoft.Azure.Commands.Network.Properties.Resources.LoadBalancerRuleName,
                    this.Name);

            WriteObject(loadBalancingRule);
        }
Пример #12
0
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            // Get the subnetId and publicIpAddressId from the object if specified
            if (string.Equals(ParameterSetName, "object"))
            {
                this.SubnetId = this.Subnet.Id;

                if (PublicIpAddress != null)
                {
                    this.PublicIpAddressId = this.PublicIpAddress.Id;
                }
            }

            var frontendIpConfig = new PSFrontendIPConfiguration();

            frontendIpConfig.Name = this.Name;

            if (!string.IsNullOrEmpty(this.SubnetId))
            {
                frontendIpConfig.Subnet    = new PSResourceId();
                frontendIpConfig.Subnet.Id = this.SubnetId;

                if (!string.IsNullOrEmpty(this.PrivateIpAddress))
                {
                    frontendIpConfig.PrivateIpAddress          = this.PrivateIpAddress;
                    frontendIpConfig.PrivateIpAllocationMethod = Management.Network.Models.IpAllocationMethod.Static;
                }
                else
                {
                    frontendIpConfig.PrivateIpAllocationMethod = Management.Network.Models.IpAllocationMethod.Dynamic;
                }
            }

            if (!string.IsNullOrEmpty(this.PublicIpAddressId))
            {
                frontendIpConfig.PublicIpAddress    = new PSResourceId();
                frontendIpConfig.PublicIpAddress.Id = this.PublicIpAddressId;
            }

            frontendIpConfig.Id =
                ChildResourceHelper.GetResourceNotSetId(
                    this.NetworkClient.NetworkResourceProviderClient.Credentials.SubscriptionId,
                    Microsoft.Azure.Commands.Network.Properties.Resources.LoadBalancerFrontendIpConfigName,
                    this.Name);

            WriteObject(frontendIpConfig);
        }
        public override void Execute()
        {
            base.Execute();
            var backendAddressPool = new PSBackendAddressPool();

            backendAddressPool.Name = this.Name;

            backendAddressPool.Id =
                ChildResourceHelper.GetResourceNotSetId(
                    this.NetworkClient.NetworkManagementClient.SubscriptionId,
                    Microsoft.Azure.Commands.Network.Properties.Resources.LoadBalancerBackendAddressPoolName,
                    this.Name);

            WriteObject(backendAddressPool);
        }
Пример #14
0
        protected override void ProcessRecord()
        {
            base.ProcessRecord();

            var backendAddressPool = new PSBackendAddressPool();

            backendAddressPool.Name = this.Name;

            backendAddressPool.Id =
                ChildResourceHelper.GetResourceNotSetId(
                    this.NetworkClient.NetworkResourceProviderClient.Credentials.SubscriptionId,
                    Microsoft.Azure.Commands.Network.Properties.Resources.LoadBalancerBackendAddressPoolName,
                    this.Name);

            WriteObject(backendAddressPool);
        }
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            var existingInboundNatRule = this.LoadBalancer.InboundNatRules.SingleOrDefault(resource => string.Equals(resource.Name, this.Name, System.StringComparison.CurrentCultureIgnoreCase));

            if (existingInboundNatRule != null)
            {
                throw new ArgumentException("InboundNatRule with the specified name already exists");
            }

            var inboundNatRule = new PSInboundNatRule();

            inboundNatRule.Name         = this.Name;
            inboundNatRule.Protocol     = this.Protocol;
            inboundNatRule.FrontendPort = this.FrontendPort;
            inboundNatRule.BackendPort  = this.BackendPort;
            if (this.IdleTimeoutInMinutes > 0)
            {
                inboundNatRule.IdleTimeoutInMinutes = this.IdleTimeoutInMinutes;
            }
            inboundNatRule.EnableFloatingIP = this.EnableFloatingIP.IsPresent;

            if (!string.IsNullOrEmpty(this.FrontendIpConfigurationId))
            {
                inboundNatRule.FrontendIPConfiguration = new PSResourceId()
                {
                    Id = this.FrontendIpConfigurationId
                };
            }

            inboundNatRule.Id =
                ChildResourceHelper.GetResourceId(
                    this.NetworkClient.NetworkResourceProviderClient.Credentials.SubscriptionId,
                    this.LoadBalancer.ResourceGroupName,
                    this.LoadBalancer.Name,
                    Microsoft.Azure.Commands.Network.Properties.Resources.LoadBalancerInBoundNatRuleName,
                    this.Name);

            this.LoadBalancer.InboundNatRules.Add(inboundNatRule);

            WriteObject(this.LoadBalancer);
        }
Пример #16
0
        public override void Execute()
        {
            base.Execute();
            var probe = new PSProbe();

            probe.Name              = this.Name;
            probe.Port              = this.Port;
            probe.Protocol          = this.Protocol;
            probe.RequestPath       = this.RequestPath;
            probe.IntervalInSeconds = this.IntervalInSeconds;
            probe.NumberOfProbes    = this.ProbeCount;

            probe.Id =
                ChildResourceHelper.GetResourceNotSetId(
                    this.NetworkClient.NetworkManagementClient.SubscriptionId,
                    Microsoft.Azure.Commands.Network.Properties.Resources.LoadBalancerProbeName,
                    this.Name);

            WriteObject(probe);
        }
        protected override void ProcessRecord()
        {
            base.ProcessRecord();

            var probe = new PSProbe();

            probe.Name              = this.Name;
            probe.Port              = this.Port;
            probe.Protocol          = this.Protocol;
            probe.RequestPath       = this.RequestPath;
            probe.IntervalInSeconds = this.IntervalInSeconds;
            probe.NumberOfProbes    = this.ProbeCount;

            probe.Id =
                ChildResourceHelper.GetResourceNotSetId(
                    this.NetworkClient.NetworkResourceProviderClient.Credentials.SubscriptionId,
                    Microsoft.Azure.Commands.Network.Properties.Resources.LoadBalancerProbeName,
                    this.Name);

            WriteObject(probe);
        }
        public override void Execute()
        {
            base.Execute();

            var frontendIpConfig = new PSFrontendIPConfiguration();

            frontendIpConfig.Name  = this.Name;
            frontendIpConfig.Zones = this.Zone;

            if (!string.IsNullOrEmpty(this.SubnetId))
            {
                frontendIpConfig.Subnet    = new PSSubnet();
                frontendIpConfig.Subnet.Id = this.SubnetId;

                if (!string.IsNullOrEmpty(this.PrivateIpAddress))
                {
                    frontendIpConfig.PrivateIpAddress          = this.PrivateIpAddress;
                    frontendIpConfig.PrivateIpAllocationMethod = Management.Network.Models.IPAllocationMethod.Static;
                }
                else
                {
                    frontendIpConfig.PrivateIpAllocationMethod = Management.Network.Models.IPAllocationMethod.Dynamic;
                }
            }

            if (!string.IsNullOrEmpty(this.PublicIpAddressId))
            {
                frontendIpConfig.PublicIpAddress    = new PSPublicIpAddress();
                frontendIpConfig.PublicIpAddress.Id = this.PublicIpAddressId;
            }

            frontendIpConfig.Id =
                ChildResourceHelper.GetResourceNotSetId(
                    this.NetworkClient.NetworkManagementClient.SubscriptionId,
                    Microsoft.Azure.Commands.Network.Properties.Resources.LoadBalancerFrontendIpConfigName,
                    this.Name);

            WriteObject(frontendIpConfig);
        }
Пример #19
0
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            var existingInboundNatPool = this.LoadBalancer.InboundNatPools.SingleOrDefault(resource => string.Equals(resource.Name, this.Name, System.StringComparison.CurrentCultureIgnoreCase));

            if (existingInboundNatPool != null)
            {
                throw new ArgumentException("InboundNatPool with the specified name already exists");
            }

            var inboundNatPool = new PSInboundNatPool();

            inboundNatPool.Name     = this.Name;
            inboundNatPool.Protocol = this.Protocol;
            inboundNatPool.FrontendPortRangeStart = this.FrontendPortRangeStart;
            inboundNatPool.FrontendPortRangeEnd   = this.FrontendPortRangeEnd;
            inboundNatPool.BackendPort            = this.BackendPort;

            if (!string.IsNullOrEmpty(this.FrontendIpConfigurationId))
            {
                inboundNatPool.FrontendIPConfiguration = new PSResourceId()
                {
                    Id = this.FrontendIpConfigurationId
                };
            }

            inboundNatPool.Id =
                ChildResourceHelper.GetResourceId(
                    this.NetworkClient.NetworkManagementClient.SubscriptionId,
                    this.LoadBalancer.ResourceGroupName,
                    this.LoadBalancer.Name,
                    Microsoft.Azure.Commands.Network.Properties.Resources.LoadBalancerInboundNatPoolsName,
                    this.Name);

            this.LoadBalancer.InboundNatPools.Add(inboundNatPool);

            WriteObject(this.LoadBalancer);
        }
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            var existingFrontendIPConfig = this.ApplicationGateway.FrontendIPConfigurations.SingleOrDefault
                                               (resource => string.Equals(resource.Name, this.Name, System.StringComparison.CurrentCultureIgnoreCase));

            if (existingFrontendIPConfig != null)
            {
                throw new ArgumentException("FrontendIPConfiguration with the specified name already exists");
            }


            // Get the subnetId and publicIPAddressId from the object if specified
            if (string.Equals(ParameterSetName, Microsoft.Azure.Commands.Network.Properties.Resources.SetByResource))
            {
                this.SubnetId = this.Subnet.Id;

                if (PublicIPAddress != null)
                {
                    this.PublicIPAddressId = this.PublicIPAddress.Id;
                }
            }

            var frontendIPConfig = new PSApplicationGatewayFrontendIPConfiguration();

            frontendIPConfig.Name = this.Name;

            if (!string.IsNullOrEmpty(this.SubnetId))
            {
                frontendIPConfig.Subnet    = new PSResourceId();
                frontendIPConfig.Subnet.Id = this.SubnetId;

                if (!string.IsNullOrEmpty(this.PrivateIPAddress))
                {
                    frontendIPConfig.PrivateIPAddress          = this.PrivateIPAddress;
                    frontendIPConfig.PrivateIPAllocationMethod = Management.Network.Models.IpAllocationMethod.Static;
                }
                else
                {
                    frontendIPConfig.PrivateIPAllocationMethod = Management.Network.Models.IpAllocationMethod.Dynamic;
                }
            }

            if (!string.IsNullOrEmpty(this.PublicIPAddressId))
            {
                frontendIPConfig.PublicIPAddress    = new PSResourceId();
                frontendIPConfig.PublicIPAddress.Id = this.PublicIPAddressId;
            }

            frontendIPConfig.Id =
                ChildResourceHelper.GetResourceId(
                    this.NetworkClient.NetworkResourceProviderClient.Credentials.SubscriptionId,
                    this.ApplicationGateway.ResourceGroupName,
                    this.ApplicationGateway.Name,
                    Microsoft.Azure.Commands.Network.Properties.Resources.ApplicationGatewayFrontendIpConfigName,
                    this.Name);

            this.ApplicationGateway.FrontendIPConfigurations.Add(frontendIPConfig);

            WriteObject(this.ApplicationGateway);
        }
        public override void Execute()
        {
            base.Execute();
            var existingLoadBalancingRule = this.LoadBalancer.LoadBalancingRules.SingleOrDefault(resource => string.Equals(resource.Name, this.Name, System.StringComparison.CurrentCultureIgnoreCase));

            if (existingLoadBalancingRule != null)
            {
                throw new ArgumentException("LoadBalancingRule with the specified name already exists");
            }

            var loadBalancingRule = new PSLoadBalancingRule();

            loadBalancingRule.Name         = this.Name;
            loadBalancingRule.Protocol     = this.Protocol;
            loadBalancingRule.FrontendPort = this.FrontendPort;
            loadBalancingRule.BackendPort  = this.BackendPort;

            if (this.IdleTimeoutInMinutes > 0)
            {
                loadBalancingRule.IdleTimeoutInMinutes = this.IdleTimeoutInMinutes;
            }

            if (!string.IsNullOrEmpty(this.LoadDistribution))
            {
                loadBalancingRule.LoadDistribution = this.LoadDistribution;
            }

            loadBalancingRule.EnableFloatingIP = this.EnableFloatingIP.IsPresent;

            if (!string.IsNullOrEmpty(this.BackendAddressPoolId))
            {
                loadBalancingRule.BackendAddressPool    = new PSResourceId();
                loadBalancingRule.BackendAddressPool.Id = this.BackendAddressPoolId;
            }

            if (!string.IsNullOrEmpty(this.ProbeId))
            {
                loadBalancingRule.Probe    = new PSResourceId();
                loadBalancingRule.Probe.Id = this.ProbeId;
            }

            if (!string.IsNullOrEmpty(this.FrontendIpConfigurationId))
            {
                loadBalancingRule.FrontendIPConfiguration = new PSResourceId()
                {
                    Id = this.FrontendIpConfigurationId
                };
            }

            loadBalancingRule.Id =
                ChildResourceHelper.GetResourceId(
                    this.NetworkClient.NetworkManagementClient.SubscriptionId,
                    this.LoadBalancer.ResourceGroupName,
                    this.LoadBalancer.Name,
                    Microsoft.Azure.Commands.Network.Properties.Resources.LoadBalancerRuleName,
                    this.Name);

            this.LoadBalancer.LoadBalancingRules.Add(loadBalancingRule);

            WriteObject(this.LoadBalancer);
        }