Example #1
0
        protected override void ProcessRecord()
        {
            base.ProcessRecord();

            var networkConfiguration = GetNetworkConfiguration();

            if (networkConfiguration == null)
            {
                throw new ArgumentOutOfRangeException(Resources.NetworkConfigurationNotFoundOnPersistentVM);
            }

            if (networkConfiguration.NetworkInterfaces == null)
            {
                networkConfiguration.NetworkInterfaces = new AssignNetworkInterfaceCollection();
            }

            // Verify if the network interface already exists
            var existingNics =
                networkConfiguration.NetworkInterfaces.Where(
                    interfaces => string.Equals(interfaces.Name, this.Name, StringComparison.OrdinalIgnoreCase)).ToList();

            if (existingNics.Any())
            {
                throw new ArgumentOutOfRangeException(Resources.DuplicateNetworkInterfaceFound);
            }

            var ipConfig = new AssignIPConfiguration();

            ipConfig.SubnetName = this.SubnetName;
            if (!string.IsNullOrEmpty(this.StaticVNetIPAddress))
            {
                ipConfig.StaticVirtualNetworkIPAddress = this.StaticVNetIPAddress;
            }

            networkConfiguration.NetworkInterfaces.Add(
                new AssignNetworkInterface()
            {
                Name             = this.Name,
                IPConfigurations = new AssignIPConfigurationCollection()
                {
                    ipConfig
                },
                NetworkSecurityGroup = this.NetworkSecurityGroup,
                IPForwarding         = this.IPForwarding,
            });
            WriteObject(VM);
        }
        protected override void ProcessRecord()
        {
            base.ProcessRecord();

            var networkConfiguration = GetNetworkConfiguration();
            if (networkConfiguration == null)
            {
                throw new ArgumentOutOfRangeException(Resources.NetworkConfigurationNotFoundOnPersistentVM);
            }

            if (networkConfiguration.NetworkInterfaces == null)
            {
                networkConfiguration.NetworkInterfaces = new AssignNetworkInterfaceCollection();
            }

            // Verify if the network interface already exists
            var existingNics =
                    networkConfiguration.NetworkInterfaces.Where(
                        interfaces => string.Equals(interfaces.Name, this.Name, StringComparison.OrdinalIgnoreCase)).ToList();

            if (existingNics.Any())
            {
                throw new ArgumentOutOfRangeException(Resources.DuplicateNetworkInterfaceFound);
            }

            var ipConfig = new AssignIPConfiguration();
            ipConfig.SubnetName = this.SubnetName;
            if (!string.IsNullOrEmpty(this.StaticVNetIPAddress))
            {
                ipConfig.StaticVirtualNetworkIPAddress = this.StaticVNetIPAddress;
            }

            networkConfiguration.NetworkInterfaces.Add(
                new AssignNetworkInterface()
                {
                    Name = this.Name,
                    IPConfigurations = new AssignIPConfigurationCollection()
                    {
                        ipConfig
                    },
                    NetworkSecurityGroup = this.NetworkSecurityGroup,
                    IPForwarding = this.IPForwarding,
                });
            WriteObject(VM);
        }