public override void Execute()
        {
            base.Execute();

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

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

                if (this.LoadBalancerBackendAddressPool != null)
                {
                    this.LoadBalancerBackendAddressPoolId = new List <string>();
                    foreach (var bepool in this.LoadBalancerBackendAddressPool)
                    {
                        this.LoadBalancerBackendAddressPoolId.Add(bepool.Id);
                    }
                }

                if (this.LoadBalancerInboundNatRule != null)
                {
                    this.LoadBalancerInboundNatRuleId = new List <string>();
                    foreach (var natRule in this.LoadBalancerInboundNatRule)
                    {
                        this.LoadBalancerInboundNatRuleId.Add(natRule.Id);
                    }
                }

                if (this.ApplicationGatewayBackendAddressPool != null)
                {
                    this.ApplicationGatewayBackendAddressPoolId = new List <string>();
                    foreach (var appgwBepool in this.ApplicationGatewayBackendAddressPool)
                    {
                        this.ApplicationGatewayBackendAddressPoolId.Add(appgwBepool.Id);
                    }
                }

                if (this.ApplicationSecurityGroup != null)
                {
                    this.ApplicationSecurityGroupId = new List <string>();
                    foreach (var asg in this.ApplicationSecurityGroup)
                    {
                        this.ApplicationSecurityGroupId.Add(asg.Id);
                    }
                }
            }

            var ipconfig = new PSNetworkInterfaceIPConfiguration();

            ipconfig.Name = this.Name;

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

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

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

            if (this.LoadBalancerBackendAddressPoolId != null)
            {
                ipconfig.LoadBalancerBackendAddressPools = new List <PSBackendAddressPool>();
                foreach (var bepoolId in this.LoadBalancerBackendAddressPoolId)
                {
                    ipconfig.LoadBalancerBackendAddressPools.Add(new PSBackendAddressPool {
                        Id = bepoolId
                    });
                }
            }

            if (this.LoadBalancerInboundNatRuleId != null)
            {
                ipconfig.LoadBalancerInboundNatRules = new List <PSInboundNatRule>();
                foreach (var natruleId in this.LoadBalancerInboundNatRuleId)
                {
                    ipconfig.LoadBalancerInboundNatRules.Add(new PSInboundNatRule {
                        Id = natruleId
                    });
                }
            }

            if (this.ApplicationGatewayBackendAddressPoolId != null)
            {
                ipconfig.ApplicationGatewayBackendAddressPools = new List <PSApplicationGatewayBackendAddressPool>();
                foreach (var appgwBepoolId in this.ApplicationGatewayBackendAddressPoolId)
                {
                    ipconfig.ApplicationGatewayBackendAddressPools.Add(new PSApplicationGatewayBackendAddressPool {
                        Id = appgwBepoolId
                    });
                }
            }

            if (this.ApplicationSecurityGroupId != null)
            {
                ipconfig.ApplicationSecurityGroups = new List <PSApplicationSecurityGroup>();
                foreach (var asgId in this.ApplicationSecurityGroupId)
                {
                    ipconfig.ApplicationSecurityGroups.Add(new PSApplicationSecurityGroup {
                        Id = asgId
                    });
                }
            }

            ipconfig.PrivateIpAddressVersion = this.PrivateIpAddressVersion;
            ipconfig.Primary = this.Primary.IsPresent;
            WriteObject(ipconfig);
        }
        private PSNetworkInterface CreateNetworkInterface()
        {
            // 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 (this.PublicIpAddress != null)
                {
                    this.PublicIpAddressId = this.PublicIpAddress.Id;
                }

                if (this.NetworkSecurityGroup != null)
                {
                    this.NetworkSecurityGroupId = this.NetworkSecurityGroup.Id;
                }

                if (this.LoadBalancerBackendAddressPool != null)
                {
                    this.LoadBalancerBackendAddressPoolId = new List <string>();
                    foreach (var bepool in this.LoadBalancerBackendAddressPool)
                    {
                        this.LoadBalancerBackendAddressPoolId.Add(bepool.Id);
                    }
                }

                if (this.LoadBalancerInboundNatRule != null)
                {
                    this.LoadBalancerInboundNatRuleId = new List <string>();
                    foreach (var natRule in this.LoadBalancerInboundNatRule)
                    {
                        this.LoadBalancerInboundNatRuleId.Add(natRule.Id);
                    }
                }

                if (this.ApplicationGatewayBackendAddressPool != null)
                {
                    this.ApplicationGatewayBackendAddressPoolId = new List <string>();
                    foreach (var appgwBepool in this.ApplicationGatewayBackendAddressPool)
                    {
                        this.ApplicationGatewayBackendAddressPoolId.Add(appgwBepool.Id);
                    }
                }
            }

            var networkInterface = new PSNetworkInterface();

            networkInterface.Name               = this.Name;
            networkInterface.Location           = this.Location;
            networkInterface.EnableIPForwarding = this.EnableIPForwarding.IsPresent;
            networkInterface.IpConfigurations   = new List <PSNetworkInterfaceIPConfiguration>();

            var nicIpConfiguration = new PSNetworkInterfaceIPConfiguration();

            nicIpConfiguration.Name = string.IsNullOrEmpty(this.IpConfigurationName) ? "ipconfig1" : this.IpConfigurationName;
            nicIpConfiguration.PrivateIpAllocationMethod = MNM.IPAllocationMethod.Dynamic;

            if (!string.IsNullOrEmpty(this.PrivateIpAddress))
            {
                nicIpConfiguration.PrivateIpAddress          = this.PrivateIpAddress;
                nicIpConfiguration.PrivateIpAllocationMethod = MNM.IPAllocationMethod.Static;
            }

            nicIpConfiguration.Subnet    = new PSSubnet();
            nicIpConfiguration.Subnet.Id = this.SubnetId;

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

            if (!string.IsNullOrEmpty(this.NetworkSecurityGroupId))
            {
                networkInterface.NetworkSecurityGroup    = new PSNetworkSecurityGroup();
                networkInterface.NetworkSecurityGroup.Id = this.NetworkSecurityGroupId;
            }

            if (this.LoadBalancerBackendAddressPoolId != null)
            {
                nicIpConfiguration.LoadBalancerBackendAddressPools = new List <PSBackendAddressPool>();
                foreach (var bepoolId in this.LoadBalancerBackendAddressPoolId)
                {
                    nicIpConfiguration.LoadBalancerBackendAddressPools.Add(new PSBackendAddressPool {
                        Id = bepoolId
                    });
                }
            }

            if (this.LoadBalancerInboundNatRuleId != null)
            {
                nicIpConfiguration.LoadBalancerInboundNatRules = new List <PSInboundNatRule>();
                foreach (var natruleId in this.LoadBalancerInboundNatRuleId)
                {
                    nicIpConfiguration.LoadBalancerInboundNatRules.Add(new PSInboundNatRule {
                        Id = natruleId
                    });
                }
            }

            if (this.ApplicationGatewayBackendAddressPoolId != null)
            {
                nicIpConfiguration.ApplicationGatewayBackendAddressPools = new List <PSApplicationGatewayBackendAddressPool>();
                foreach (var appgwBepoolId in this.ApplicationGatewayBackendAddressPoolId)
                {
                    nicIpConfiguration.ApplicationGatewayBackendAddressPools.Add(new PSApplicationGatewayBackendAddressPool {
                        Id = appgwBepoolId
                    });
                }
            }

            if (this.DnsServer != null || this.InternalDnsNameLabel != null)
            {
                networkInterface.DnsSettings = new PSNetworkInterfaceDnsSettings();
                if (this.DnsServer != null)
                {
                    networkInterface.DnsSettings.DnsServers = this.DnsServer;
                }
                if (this.InternalDnsNameLabel != null)
                {
                    networkInterface.DnsSettings.InternalDnsNameLabel = this.InternalDnsNameLabel;
                }
            }

            networkInterface.IpConfigurations.Add(nicIpConfiguration);

            var networkInterfaceModel = Mapper.Map <MNM.NetworkInterface>(networkInterface);

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

            this.NetworkInterfaceClient.CreateOrUpdate(this.ResourceGroupName, this.Name, networkInterfaceModel);

            var getNetworkInterface = this.GetNetworkInterface(this.ResourceGroupName, this.Name);

            return(getNetworkInterface);
        }
Example #3
0
        private PSNetworkInterface CreateNetworkInterface()
        {
            var networkInterface = new PSNetworkInterface();

            networkInterface.Name = this.Name;

            networkInterface.Location = this.Location;

            networkInterface.EnableIPForwarding          = this.EnableIPForwarding.IsPresent;
            networkInterface.EnableAcceleratedNetworking = this.EnableAcceleratedNetworking.IsPresent;

            // Get the subnetId and publicIpAddressId from the object if specified
            if (ParameterSetName.Contains(Microsoft.Azure.Commands.Network.Properties.Resources.SetByIpConfiguration))
            {
                networkInterface.IpConfigurations = this.IpConfiguration?.ToList();

                if (string.Equals(ParameterSetName, Microsoft.Azure.Commands.Network.Properties.Resources.SetByIpConfigurationResourceId))
                {
                    if (this.NetworkSecurityGroup != null)
                    {
                        this.NetworkSecurityGroupId = this.NetworkSecurityGroup.Id;
                    }
                }
            }
            else
            {
                if (string.Equals(ParameterSetName, Microsoft.Azure.Commands.Network.Properties.Resources.SetByResource))
                {
                    this.SubnetId = this.Subnet.Id;

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

                    if (this.NetworkSecurityGroup != null)
                    {
                        this.NetworkSecurityGroupId = this.NetworkSecurityGroup.Id;
                    }

                    if (this.LoadBalancerBackendAddressPool != null)
                    {
                        var poolIds = new List <string>();
                        foreach (var bepool in this.LoadBalancerBackendAddressPool)
                        {
                            poolIds.Add(bepool.Id);
                        }
                        this.LoadBalancerBackendAddressPoolId = poolIds.ToArray();
                    }

                    if (this.LoadBalancerInboundNatRule != null)
                    {
                        var lbNatIds = new List <string>();
                        foreach (var natRule in this.LoadBalancerInboundNatRule)
                        {
                            lbNatIds.Add(natRule.Id);
                        }
                        LoadBalancerInboundNatRuleId = lbNatIds.ToArray();
                    }

                    if (this.ApplicationGatewayBackendAddressPool != null)
                    {
                        var appGwPoolIds = new List <string>();
                        foreach (var appgwBepool in this.ApplicationGatewayBackendAddressPool)
                        {
                            appGwPoolIds.Add(appgwBepool.Id);
                        }
                        ApplicationGatewayBackendAddressPoolId = appGwPoolIds.ToArray();
                    }

                    if (this.ApplicationSecurityGroup != null)
                    {
                        var groupIds = new List <string>();
                        foreach (var asg in this.ApplicationSecurityGroup)
                        {
                            groupIds.Add(asg.Id);
                        }
                        ApplicationSecurityGroupId = groupIds.ToArray();
                    }
                }

                var nicIpConfiguration = new PSNetworkInterfaceIPConfiguration();
                nicIpConfiguration.Name = string.IsNullOrEmpty(this.IpConfigurationName) ? "ipconfig1" : this.IpConfigurationName;
                nicIpConfiguration.PrivateIpAllocationMethod = MNM.IPAllocationMethod.Dynamic;
                nicIpConfiguration.Primary = true;
                // Uncomment when ipv6 is supported as standalone ipconfig in a nic
                // nicIpConfiguration.PrivateIpAddressVersion = this.PrivateIpAddressVersion;

                if (!string.IsNullOrEmpty(this.PrivateIpAddress))
                {
                    nicIpConfiguration.PrivateIpAddress          = this.PrivateIpAddress;
                    nicIpConfiguration.PrivateIpAllocationMethod = MNM.IPAllocationMethod.Static;
                }

                nicIpConfiguration.Subnet    = new PSSubnet();
                nicIpConfiguration.Subnet.Id = this.SubnetId;

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

                if (this.LoadBalancerBackendAddressPoolId != null)
                {
                    nicIpConfiguration.LoadBalancerBackendAddressPools = new List <PSBackendAddressPool>();
                    foreach (var bepoolId in this.LoadBalancerBackendAddressPoolId)
                    {
                        nicIpConfiguration.LoadBalancerBackendAddressPools.Add(new PSBackendAddressPool {
                            Id = bepoolId
                        });
                    }
                }

                if (this.LoadBalancerInboundNatRuleId != null)
                {
                    nicIpConfiguration.LoadBalancerInboundNatRules = new List <PSInboundNatRule>();
                    foreach (var natruleId in this.LoadBalancerInboundNatRuleId)
                    {
                        nicIpConfiguration.LoadBalancerInboundNatRules.Add(new PSInboundNatRule {
                            Id = natruleId
                        });
                    }
                }

                if (this.ApplicationGatewayBackendAddressPoolId != null)
                {
                    nicIpConfiguration.ApplicationGatewayBackendAddressPools = new List <PSApplicationGatewayBackendAddressPool>();
                    foreach (var appgwBepoolId in this.ApplicationGatewayBackendAddressPoolId)
                    {
                        nicIpConfiguration.ApplicationGatewayBackendAddressPools.Add(new PSApplicationGatewayBackendAddressPool {
                            Id = appgwBepoolId
                        });
                    }
                }

                if (this.ApplicationSecurityGroupId != null)
                {
                    nicIpConfiguration.ApplicationSecurityGroups = new List <PSApplicationSecurityGroup>();
                    foreach (var id in this.ApplicationSecurityGroupId)
                    {
                        nicIpConfiguration.ApplicationSecurityGroups.Add(new PSApplicationSecurityGroup {
                            Id = id
                        });
                    }
                }

                networkInterface.IpConfigurations = new List <PSNetworkInterfaceIPConfiguration>();
                networkInterface.IpConfigurations.Add(nicIpConfiguration);
            }

            if (this.DnsServer != null || this.InternalDnsNameLabel != null)
            {
                networkInterface.DnsSettings = new PSNetworkInterfaceDnsSettings();
                if (this.DnsServer != null)
                {
                    networkInterface.DnsSettings.DnsServers = this.DnsServer?.ToList();
                }
                if (this.InternalDnsNameLabel != null)
                {
                    networkInterface.DnsSettings.InternalDnsNameLabel = this.InternalDnsNameLabel;
                }
            }

            if (!string.IsNullOrEmpty(this.NetworkSecurityGroupId))
            {
                networkInterface.NetworkSecurityGroup    = new PSNetworkSecurityGroup();
                networkInterface.NetworkSecurityGroup.Id = this.NetworkSecurityGroupId;
            }

            var networkInterfaceModel = NetworkResourceManagerProfile.Mapper.Map <MNM.NetworkInterface>(networkInterface);

            this.NullifyApplicationSecurityGroupIfAbsent(networkInterfaceModel);

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

            this.NetworkInterfaceClient.CreateOrUpdate(this.ResourceGroupName, this.Name, networkInterfaceModel);

            var getNetworkInterface = this.GetNetworkInterface(this.ResourceGroupName, this.Name);

            return(getNetworkInterface);
        }
        public override void Execute()
        {
            base.Execute();

            var existingIpConfig = this.NetworkInterface.IpConfigurations.SingleOrDefault(resource => string.Equals(resource.Name, this.Name, System.StringComparison.CurrentCultureIgnoreCase));

            if (existingIpConfig != null)
            {
                throw new ArgumentException("IpConfiguration 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))
            {
                if (this.Subnet != null)
                {
                    this.SubnetId = this.Subnet.Id;
                }

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

                if (this.LoadBalancerBackendAddressPool != null)
                {
                    var poolIds = new List <string>();
                    foreach (var bepool in this.LoadBalancerBackendAddressPool)
                    {
                        poolIds.Add(bepool.Id);
                    }
                    this.LoadBalancerBackendAddressPoolId = poolIds.ToArray();
                }

                if (this.LoadBalancerInboundNatRule != null)
                {
                    var lbNatIds = new List <string>();
                    foreach (var natRule in this.LoadBalancerInboundNatRule)
                    {
                        lbNatIds.Add(natRule.Id);
                    }
                    LoadBalancerInboundNatRuleId = lbNatIds.ToArray();
                }

                if (this.ApplicationGatewayBackendAddressPool != null)
                {
                    var appGwPoolIds = new List <string>();
                    foreach (var appgwBepool in this.ApplicationGatewayBackendAddressPool)
                    {
                        appGwPoolIds.Add(appgwBepool.Id);
                    }
                    ApplicationGatewayBackendAddressPoolId = appGwPoolIds.ToArray();
                }

                if (this.ApplicationSecurityGroup != null)
                {
                    var groupIds = new List <string>();
                    foreach (var asg in this.ApplicationSecurityGroup)
                    {
                        groupIds.Add(asg.Id);
                    }
                    ApplicationSecurityGroupId = groupIds.ToArray();
                }
            }

            var ipconfig = new PSNetworkInterfaceIPConfiguration();

            ipconfig.Name = this.Name;
            if (this.Primary.IsPresent)
            {
                foreach (var item in NetworkInterface.IpConfigurations)
                {
                    item.Primary = false;
                }

                ipconfig.Primary = this.Primary.IsPresent;
            }

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

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

            if (!string.IsNullOrEmpty(this.GatewayLoadBalancerId))
            {
                // Gateway
                if (ipconfig.GatewayLoadBalancer == null)
                {
                    ipconfig.GatewayLoadBalancer = new PSFrontendIPConfiguration();
                }
                ipconfig.GatewayLoadBalancer.Id = this.GatewayLoadBalancerId;
            }

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

            if (this.LoadBalancerBackendAddressPoolId != null)
            {
                ipconfig.LoadBalancerBackendAddressPools = new List <PSBackendAddressPool>();
                foreach (var bepoolId in this.LoadBalancerBackendAddressPoolId)
                {
                    ipconfig.LoadBalancerBackendAddressPools.Add(new PSBackendAddressPool {
                        Id = bepoolId
                    });
                }
            }

            if (this.LoadBalancerInboundNatRuleId != null)
            {
                ipconfig.LoadBalancerInboundNatRules = new List <PSInboundNatRule>();
                foreach (var natruleId in this.LoadBalancerInboundNatRuleId)
                {
                    ipconfig.LoadBalancerInboundNatRules.Add(new PSInboundNatRule {
                        Id = natruleId
                    });
                }
            }

            if (this.ApplicationGatewayBackendAddressPoolId != null)
            {
                ipconfig.ApplicationGatewayBackendAddressPools = new List <PSApplicationGatewayBackendAddressPool>();
                foreach (var appgwBepoolId in this.ApplicationGatewayBackendAddressPoolId)
                {
                    ipconfig.ApplicationGatewayBackendAddressPools.Add(new PSApplicationGatewayBackendAddressPool {
                        Id = appgwBepoolId
                    });
                }
            }

            if (this.ApplicationSecurityGroupId != null)
            {
                ipconfig.ApplicationSecurityGroups = new List <PSApplicationSecurityGroup>();
                foreach (var asgId in this.ApplicationSecurityGroupId)
                {
                    ipconfig.ApplicationSecurityGroups.Add(new PSApplicationSecurityGroup {
                        Id = asgId
                    });
                }
            }

            ipconfig.PrivateIpAddressVersion = this.PrivateIpAddressVersion;

            this.NetworkInterface.IpConfigurations.Add(ipconfig);

            WriteObject(this.NetworkInterface);
        }
Example #5
0
        public override void Execute()
        {
            base.Execute();

            // DestinationNetworkInterfaceIPConfiguration
            PSNetworkInterfaceIPConfiguration vDestinationNetworkInterfaceIPConfiguration = null;

            // DestinationLoadBalancerFrontEndIPConfiguration
            PSFrontendIPConfiguration vDestinationLoadBalancerFrontEndIPConfiguration = null;


            if (string.Equals(ParameterSetName, Microsoft.Azure.Commands.Network.Properties.Resources.SetByResource))
            {
                if (this.DestinationNetworkInterfaceIPConfiguration != null)
                {
                    this.DestinationNetworkInterfaceIPConfigurationId = this.DestinationNetworkInterfaceIPConfiguration.Id;
                }
                if (this.DestinationLoadBalancerFrontEndIPConfiguration != null)
                {
                    this.DestinationLoadBalancerFrontEndIPConfigurationId = this.DestinationLoadBalancerFrontEndIPConfiguration.Id;
                }
            }

            if (this.DestinationNetworkInterfaceIPConfigurationId != null)
            {
                if (vDestinationNetworkInterfaceIPConfiguration == null)
                {
                    vDestinationNetworkInterfaceIPConfiguration = new PSNetworkInterfaceIPConfiguration();
                }
                vDestinationNetworkInterfaceIPConfiguration.Id = this.DestinationNetworkInterfaceIPConfigurationId;
            }

            if (this.DestinationLoadBalancerFrontEndIPConfigurationId != null)
            {
                if (vDestinationLoadBalancerFrontEndIPConfiguration == null)
                {
                    vDestinationLoadBalancerFrontEndIPConfiguration = new PSFrontendIPConfiguration();
                }
                vDestinationLoadBalancerFrontEndIPConfiguration.Id = this.DestinationLoadBalancerFrontEndIPConfigurationId;
            }


            var vVirtualNetworkTap = new PSVirtualNetworkTap
            {
                DestinationPort = this.DestinationPort,
                Location        = this.Location,
                DestinationNetworkInterfaceIPConfiguration     = vDestinationNetworkInterfaceIPConfiguration,
                DestinationLoadBalancerFrontEndIPConfiguration = vDestinationLoadBalancerFrontEndIPConfiguration,
            };

            var vVirtualNetworkTapModel = NetworkResourceManagerProfile.Mapper.Map <MNM.VirtualNetworkTap>(vVirtualNetworkTap);

            vVirtualNetworkTapModel.Tags = TagsConversionHelper.CreateTagDictionary(this.Tag, validate: true);
            var present = true;

            try
            {
                this.NetworkClient.NetworkManagementClient.VirtualNetworkTaps.Get(this.ResourceGroupName, this.Name);
            }
            catch (Microsoft.Rest.Azure.CloudException exception)
            {
                if (exception.Response.StatusCode == HttpStatusCode.NotFound)
                {
                    // Resource is not present
                    present = false;
                }
                else
                {
                    throw;
                }
            }

            ConfirmAction(
                Force.IsPresent,
                string.Format(Properties.Resources.OverwritingResource, Name),
                Properties.Resources.CreatingResourceMessage,
                Name,
                () =>
            {
                this.NetworkClient.NetworkManagementClient.VirtualNetworkTaps.CreateOrUpdate(this.ResourceGroupName, this.Name, vVirtualNetworkTapModel);
                var getVirtualNetworkTap = this.NetworkClient.NetworkManagementClient.VirtualNetworkTaps.Get(this.ResourceGroupName, this.Name);
                var psVirtualNetworkTap  = NetworkResourceManagerProfile.Mapper.Map <PSVirtualNetworkTap>(getVirtualNetworkTap);
                psVirtualNetworkTap.ResourceGroupName = this.ResourceGroupName;
                psVirtualNetworkTap.Tag = TagsConversionHelper.CreateTagHashtable(getVirtualNetworkTap.Tags);
                WriteObject(psVirtualNetworkTap, true);
            },
                () => present);
        }