public override void Execute()
        {
            var vOutboundRulesIndex = this.LoadBalancer.OutboundRules.IndexOf(
                this.LoadBalancer.OutboundRules.SingleOrDefault(
                    resource => string.Equals(resource.Name, this.Name, System.StringComparison.CurrentCultureIgnoreCase)));

            if (vOutboundRulesIndex == -1)
            {
                throw new ArgumentException("OutboundRules with the specified name does not exist");
            }

            if (string.Equals(ParameterSetName, Microsoft.Azure.Commands.Network.Properties.Resources.SetByResource))
            {
                if (this.BackendAddressPool != null)
                {
                    this.BackendAddressPoolId = this.BackendAddressPool.Id;
                }
            }
            var vOutboundRules = new PSOutboundRule();

            vOutboundRules.AllocatedOutboundPorts = this.AllocatedOutboundPort;
            vOutboundRules.Protocol             = this.Protocol;
            vOutboundRules.EnableTcpReset       = this.EnableTcpReset;
            vOutboundRules.IdleTimeoutInMinutes = this.MyInvocation.BoundParameters.ContainsKey("IdleTimeoutInMinutes") ? this.IdleTimeoutInMinutes : 4;
            vOutboundRules.Name = this.Name;
            if (this.FrontendIpConfiguration?.ToList() != null && this.FrontendIpConfiguration?.ToList().Count > 0)
            {
                vOutboundRules.FrontendIpConfigurations = new List <PSResourceId>();
                foreach (var resource in this.FrontendIpConfiguration?.ToList())
                {
                    vOutboundRules.FrontendIpConfigurations.Add(
                        new PSResourceId()
                    {
                        Id = resource.Id
                    });
                }
            }
            if (!string.IsNullOrEmpty(this.BackendAddressPoolId))
            {
                // BackendAddressPool
                if (vOutboundRules.BackendAddressPool == null)
                {
                    vOutboundRules.BackendAddressPool = new PSResourceId();
                }
                vOutboundRules.BackendAddressPool.Id = this.BackendAddressPoolId;
            }
            this.LoadBalancer.OutboundRules[vOutboundRulesIndex] = vOutboundRules;
            WriteObject(this.LoadBalancer, true);
        }
        public override void Execute()
        {
            if (string.Equals(ParameterSetName, Microsoft.Azure.Commands.Network.Properties.Resources.SetByResource))
            {
                if (this.BackendAddressPool != null)
                {
                    this.BackendAddressPoolId = this.BackendAddressPool.Id;
                }
            }
            var vOutboundRules = new PSOutboundRule();

            vOutboundRules.AllocatedOutboundPorts = this.AllocatedOutboundPort;
            vOutboundRules.Protocol             = this.Protocol;
            vOutboundRules.EnableTcpReset       = this.EnableTcpReset;
            vOutboundRules.IdleTimeoutInMinutes = this.MyInvocation.BoundParameters.ContainsKey("IdleTimeoutInMinutes") ? this.IdleTimeoutInMinutes : 4;
            vOutboundRules.Name = this.Name;
            if (this.FrontendIpConfiguration != null && this.FrontendIpConfiguration.Count > 0)
            {
                vOutboundRules.FrontendIpConfigurations = new List <PSResourceId>();
                foreach (var resource in this.FrontendIpConfiguration)
                {
                    vOutboundRules.FrontendIpConfigurations.Add(
                        new PSResourceId()
                    {
                        Id = resource.Id
                    });
                }
            }
            if (!string.IsNullOrEmpty(this.BackendAddressPoolId))
            {
                // BackendAddressPool
                if (vOutboundRules.BackendAddressPool == null)
                {
                    vOutboundRules.BackendAddressPool = new PSResourceId();
                }
                vOutboundRules.BackendAddressPool.Id = this.BackendAddressPoolId;
            }
            var generatedId = string.Format(
                "/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Network/loadBalancers/{2}/{3}/{4}",
                this.NetworkClient.NetworkManagementClient.SubscriptionId,
                Microsoft.Azure.Commands.Network.Properties.Resources.ResourceGroupNotSet,
                Microsoft.Azure.Commands.Network.Properties.Resources.LoadBalancerNameNotSet,
                "OutboundRules",
                this.Name);

            vOutboundRules.Id = generatedId;

            WriteObject(vOutboundRules, true);
        }
        public override void Execute()
        {
            var existingOutboundRule = this.LoadBalancer.OutboundRules.SingleOrDefault(resource => string.Equals(resource.Name, this.Name, System.StringComparison.CurrentCultureIgnoreCase));

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

            // OutboundRules
            if (this.LoadBalancer.OutboundRules == null)
            {
                this.LoadBalancer.OutboundRules = new List <PSOutboundRule>();
            }

            if (string.Equals(ParameterSetName, Microsoft.Azure.Commands.Network.Properties.Resources.SetByResource))
            {
                if (this.BackendAddressPool != null)
                {
                    this.BackendAddressPoolId = this.BackendAddressPool.Id;
                }
            }

            var vOutboundRules = new PSOutboundRule();

            vOutboundRules.AllocatedOutboundPorts = this.AllocatedOutboundPort;
            vOutboundRules.Protocol             = this.Protocol;
            vOutboundRules.EnableTcpReset       = this.EnableTcpReset;
            vOutboundRules.IdleTimeoutInMinutes = this.MyInvocation.BoundParameters.ContainsKey("IdleTimeoutInMinutes") ? this.IdleTimeoutInMinutes : 4;
            vOutboundRules.Name = this.Name;
            if (this.FrontendIpConfiguration != null && this.FrontendIpConfiguration.Count > 0)
            {
                vOutboundRules.FrontendIpConfigurations = new List <PSResourceId>();
                foreach (var resource in this.FrontendIpConfiguration)
                {
                    vOutboundRules.FrontendIpConfigurations.Add(
                        new PSResourceId()
                    {
                        Id = resource.Id
                    });
                }
            }
            if (!string.IsNullOrEmpty(this.BackendAddressPoolId))
            {
                // BackendAddressPool
                if (vOutboundRules.BackendAddressPool == null)
                {
                    vOutboundRules.BackendAddressPool = new PSResourceId();
                }
                vOutboundRules.BackendAddressPool.Id = this.BackendAddressPoolId;
            }
            var generatedId = string.Format(
                "/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Network/loadBalancers/{2}/{3}/{4}",
                this.NetworkClient.NetworkManagementClient.SubscriptionId,
                this.LoadBalancer.ResourceGroupName,
                this.LoadBalancer.Name,
                "OutboundRules",
                this.Name);

            vOutboundRules.Id = generatedId;

            this.LoadBalancer.OutboundRules.Add(vOutboundRules);
            WriteObject(this.LoadBalancer, true);
        }