Exemplo n.º 1
0
        protected override void ProcessRecord()
        {
            if (ParameterSetName != ParameterSet1Name &&
                ParameterSetName != ParameterSet2Name &&
                ParameterSetName != ParameterSet3Name &&
                ParameterSetName != ParameterSet4Name)
            {
                throw new ValidationMetadataException("Please input web app and certificate.");
            }

            if (ParameterSetName == ParameterSet3Name ||
                ParameterSetName == ParameterSet4Name)
            {
                CmdletHelpers.ExtractWebAppPropertiesFromWebApp(WebApp, out resourceGroupName, out webAppName, out slot);
            }
            else
            {
                resourceGroupName = ResourceGroupName;
                webAppName        = WebAppName;
                slot = Slot;
            }

            string thumbPrint = null;
            var    webapp     = new PSSite(WebsitesClient.GetWebApp(resourceGroupName, webAppName, slot));

            switch (ParameterSetName)
            {
            case ParameterSet1Name:
            case ParameterSet3Name:
                var certificateBytes   = File.ReadAllBytes(CertificateFilePath);
                var certificateDetails = new X509Certificate2(certificateBytes, CertificatePassword);

                var certificateName = GenerateCertName(certificateDetails.Thumbprint, webapp.HostingEnvironmentProfile != null ? webapp.HostingEnvironmentProfile.Name : null, webapp.Location, resourceGroupName);
                var certificate     = new Certificate(
                    webapp.Location,
                    pfxBlob: certificateBytes,
                    password: CertificatePassword,
                    hostingEnvironmentProfile: webapp.HostingEnvironmentProfile ?? null,
                    serverFarmId: webapp.ServerFarmId);

                try
                {
                    WebsitesClient.CreateCertificate(resourceGroupName, certificateName, certificate);
                }
                catch (CloudException e)
                {
                    // This exception is thrown when certificate already exists. Let's swallow it and continue.
                    if (e.Response.StatusCode != HttpStatusCode.Conflict)
                    {
                        throw;
                    }
                }

                thumbPrint = certificateDetails.Thumbprint;
                break;

            case ParameterSet2Name:
            case ParameterSet4Name:
                thumbPrint = Thumbprint;
                break;
            }

            WriteObject(CmdletHelpers.GetHostNameSslStatesFromSiteResponse(
                            WebsitesClient.UpdateHostNameSslState(
                                resourceGroupName,
                                webAppName,
                                slot,
                                webapp.Location,
                                Name,
                                SslState.HasValue ? SslState.Value : Management.WebSites.Models.SslState.SniEnabled,
                                thumbPrint),
                            Name));
        }
Exemplo n.º 2
0
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();
            SiteConfig siteConfig = null;
            Site       site       = null;
            string     location   = null;

            switch (ParameterSetName)
            {
            case ParameterSet1Name:
                WebApp   = new PSSite(WebsitesClient.GetWebApp(ResourceGroupName, Name, null));
                location = WebApp.Location;
                var parameters = new HashSet <string>(MyInvocation.BoundParameters.Keys, StringComparer.OrdinalIgnoreCase);
                if (parameters.Any(p => CmdletHelpers.SiteConfigParameters.Contains(p)))
                {
                    siteConfig = new SiteConfig
                    {
                        DefaultDocuments      = parameters.Contains("DefaultDocuments") ? DefaultDocuments : null,
                        NetFrameworkVersion   = parameters.Contains("NetFrameworkVersion") ? NetFrameworkVersion : null,
                        PhpVersion            = parameters.Contains("PhpVersion") ? PhpVersion.ToLower() == "off" ? "" : PhpVersion : null,
                        RequestTracingEnabled =
                            parameters.Contains("RequestTracingEnabled") ? (bool?)RequestTracingEnabled : null,
                        HttpLoggingEnabled          = parameters.Contains("HttpLoggingEnabled") ? (bool?)HttpLoggingEnabled : null,
                        DetailedErrorLoggingEnabled =
                            parameters.Contains("DetailedErrorLoggingEnabled") ? (bool?)DetailedErrorLoggingEnabled : null,
                        HandlerMappings     = parameters.Contains("HandlerMappings") ? HandlerMappings : null,
                        ManagedPipelineMode =
                            parameters.Contains("ManagedPipelineMode")
                                    ? (ManagedPipelineMode?)Enum.Parse(typeof(ManagedPipelineMode), ManagedPipelineMode)
                                    : null,
                        WebSocketsEnabled     = parameters.Contains("WebSocketsEnabled") ? (bool?)WebSocketsEnabled : null,
                        Use32BitWorkerProcess =
                            parameters.Contains("Use32BitWorkerProcess") ? (bool?)Use32BitWorkerProcess : null,
                        AutoSwapSlotName = parameters.Contains("AutoSwapSlotName") ? AutoSwapSlotName : null,
                        NumberOfWorkers  = parameters.Contains("NumberOfWorkers") ? NumberOfWorkers : WebApp.SiteConfig.NumberOfWorkers
                    };
                }

                Hashtable appSettings = AppSettings ?? new Hashtable();

                if (siteConfig == null)
                {
                    siteConfig = WebApp.SiteConfig;
                }

                //According to current implementation if AppSettings paramter is provided we are overriding existing AppSettings
                if (WebApp.SiteConfig.AppSettings != null && AppSettings == null)
                {
                    foreach (var setting in WebApp.SiteConfig.AppSettings)
                    {
                        appSettings[setting.Name] = setting.Value;
                    }
                }

                if (ContainerImageName != null)
                {
                    string dockerImage = CmdletHelpers.DockerImagePrefix + ContainerImageName;
                    if (WebApp.IsXenon.GetValueOrDefault())
                    {
                        siteConfig.WindowsFxVersion = dockerImage;
                    }
                    else if (WebApp.Reserved.GetValueOrDefault())
                    {
                        siteConfig.LinuxFxVersion = dockerImage;
                    }
                }


                if (ContainerRegistryUrl != null)
                {
                    appSettings[CmdletHelpers.DocerRegistryServerUrl] = ContainerRegistryUrl;
                }
                if (ContainerRegistryUser != null)
                {
                    appSettings[CmdletHelpers.DocerRegistryServerUserName] = ContainerRegistryUser;
                }
                if (ContainerRegistryPassword != null)
                {
                    appSettings[CmdletHelpers.DocerRegistryServerPassword] = ContainerRegistryPassword.ConvertToString();
                }

                if (parameters.Contains("EnableContainerContinuousDeployment"))
                {
                    if (EnableContainerContinuousDeployment)
                    {
                        appSettings[CmdletHelpers.DockerEnableCI] = "true";
                    }
                    else
                    {
                        appSettings.Remove(CmdletHelpers.DockerEnableCI);
                    }
                }

                // Update web app configuration
                WebsitesClient.UpdateWebAppConfiguration(ResourceGroupName, location, Name, null, siteConfig, appSettings.ConvertToStringDictionary(), ConnectionStrings.ConvertToConnectionStringDictionary());

                //Update WebApp object after configuration update
                WebApp = new PSSite(WebsitesClient.GetWebApp(ResourceGroupName, Name, null));

                if (parameters.Any(p => CmdletHelpers.SiteParameters.Contains(p)))
                {
                    site = new Site
                    {
                        Location     = location,
                        ServerFarmId = WebApp.ServerFarmId,
                        Identity     = parameters.Contains("AssignIdentity") ? AssignIdentity ? new ManagedServiceIdentity("SystemAssigned", null, null) : new ManagedServiceIdentity("None", null, null) : WebApp.Identity,
                        HttpsOnly    = parameters.Contains("HttpsOnly") ? HttpsOnly : WebApp.HttpsOnly
                    };

                    WebsitesClient.UpdateWebApp(ResourceGroupName, location, Name, null, WebApp.ServerFarmId, new PSSite(site));
                }

                if (parameters.Contains("AppServicePlan"))
                {
                    WebsitesClient.UpdateWebApp(ResourceGroupName, location, Name, null, AppServicePlan);
                }

                if (parameters.Contains("HostNames"))
                {
                    WebsitesClient.AddCustomHostNames(ResourceGroupName, location, Name, HostNames);
                }

                break;

            case ParameterSet2Name:
                // Web app is direct or pipeline input
                string servicePlanName;
                string rg;
                location   = WebApp.Location;
                siteConfig = WebApp.SiteConfig;

                // Update web app configuration
                WebsitesClient.UpdateWebAppConfiguration(
                    ResourceGroupName,
                    location,
                    Name,
                    null,
                    siteConfig,
                    WebApp.SiteConfig == null ? null : WebApp.SiteConfig
                    .AppSettings
                    .ToDictionary(
                        nvp => nvp.Name,
                        nvp => nvp.Value,
                        StringComparer.OrdinalIgnoreCase),
                    WebApp.SiteConfig?.ConnectionStrings
                    .ToDictionary(
                        nvp => nvp.Name,
                        nvp => new ConnStringValueTypePair
                {
                    Type  = nvp.Type.Value,
                    Value = nvp.ConnectionString
                },
                        StringComparer.OrdinalIgnoreCase));

                CmdletHelpers.TryParseAppServicePlanMetadataFromResourceId(WebApp.ServerFarmId, out rg, out servicePlanName);
                WebsitesClient.UpdateWebApp(ResourceGroupName, location, Name, null, servicePlanName);
                WebsitesClient.AddCustomHostNames(ResourceGroupName, location, Name, WebApp.HostNames.ToArray());
                break;
            }

            WriteObject(new PSSite(WebsitesClient.GetWebApp(ResourceGroupName, Name, null)));
        }
Exemplo n.º 3
0
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();
            SiteConfig siteConfig = null;
            string     location   = null;

            switch (ParameterSetName)
            {
            case ParameterSet1Name:
                WebApp   = WebsitesClient.GetWebApp(ResourceGroupName, Name, null);
                location = WebApp.Location;
                var parameters = new HashSet <string>(MyInvocation.BoundParameters.Keys, StringComparer.OrdinalIgnoreCase);
                if (parameters.Any(p => CmdletHelpers.SiteConfigParameters.Contains(p)))
                {
                    siteConfig = new SiteConfig
                    {
                        DefaultDocuments      = parameters.Contains("DefaultDocuments") ? DefaultDocuments : null,
                        NetFrameworkVersion   = parameters.Contains("NetFrameworkVersion") ? NetFrameworkVersion : null,
                        PhpVersion            = parameters.Contains("PhpVersion") ? PhpVersion : null,
                        RequestTracingEnabled =
                            parameters.Contains("RequestTracingEnabled") ? (bool?)RequestTracingEnabled : null,
                        HttpLoggingEnabled          = parameters.Contains("HttpLoggingEnabled") ? (bool?)HttpLoggingEnabled : null,
                        DetailedErrorLoggingEnabled =
                            parameters.Contains("DetailedErrorLoggingEnabled") ? (bool?)DetailedErrorLoggingEnabled : null,
                        HandlerMappings     = parameters.Contains("HandlerMappings") ? HandlerMappings : null,
                        ManagedPipelineMode =
                            parameters.Contains("ManagedPipelineMode")
                                    ? (ManagedPipelineMode?)Enum.Parse(typeof(ManagedPipelineMode), ManagedPipelineMode)
                                    : null,
                        WebSocketsEnabled     = parameters.Contains("WebSocketsEnabled") ? (bool?)WebSocketsEnabled : null,
                        Use32BitWorkerProcess =
                            parameters.Contains("Use32BitWorkerProcess") ? (bool?)Use32BitWorkerProcess : null,
                        AutoSwapSlotName = parameters.Contains("AutoSwapSlotName") ? AutoSwapSlotName : null,
                        NumberOfWorkers  = parameters.Contains("NumberOfWorkers") ? NumberOfWorkers : WebApp.SiteConfig.NumberOfWorkers
                    };
                }

                // Update web app configuration
                WebsitesClient.UpdateWebAppConfiguration(ResourceGroupName, location, Name, null, siteConfig, AppSettings.ConvertToStringDictionary(), ConnectionStrings.ConvertToConnectionStringDictionary());

                if (parameters.Contains("AppServicePlan"))
                {
                    WebsitesClient.UpdateWebApp(ResourceGroupName, location, Name, null, AppServicePlan);
                }

                if (parameters.Contains("HostNames"))
                {
                    WebsitesClient.AddCustomHostNames(ResourceGroupName, location, Name, HostNames);
                }

                break;

            case ParameterSet2Name:
                // Web app is direct or pipeline input
                string servicePlanName;
                string rg;
                location   = WebApp.Location;
                siteConfig = WebApp.SiteConfig;

                // Update web app configuration
                WebsitesClient.UpdateWebAppConfiguration(ResourceGroupName, location, Name, null, siteConfig, WebApp.SiteConfig == null ? null : WebApp.SiteConfig.AppSettings.ToDictionary(nvp => nvp.Name, nvp => nvp.Value, StringComparer.OrdinalIgnoreCase), WebApp.SiteConfig == null ? null : WebApp.SiteConfig.ConnectionStrings.ToDictionary(nvp => nvp.Name, nvp => new ConnStringValueTypePair {
                    Type = nvp.Type, Value = nvp.ConnectionString
                }, StringComparer.OrdinalIgnoreCase));

                CmdletHelpers.TryParseAppServicePlanMetadataFromResourceId(WebApp.ServerFarmId, out rg, out servicePlanName);
                WebsitesClient.UpdateWebApp(ResourceGroupName, location, Name, null, servicePlanName);
                WebsitesClient.AddCustomHostNames(ResourceGroupName, location, Name, WebApp.HostNames.ToArray());
                break;
            }

            WriteObject(WebsitesClient.GetWebApp(ResourceGroupName, Name, null));
        }
Exemplo n.º 4
0
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();
            switch (ParameterSetName)
            {
            case ParameterSet1Name:
                AppServicePlan              = new PSAppServicePlan(WebsitesClient.GetAppServicePlan(ResourceGroupName, Name));
                AppServicePlan.Sku.Tier     = string.IsNullOrWhiteSpace(Tier) ? AppServicePlan.Sku.Tier : Tier;
                AppServicePlan.Sku.Capacity = NumberofWorkers > 0 ? NumberofWorkers : AppServicePlan.Sku.Capacity;
                int workerSizeAsNumber = 0;
                int.TryParse(Regex.Match(AppServicePlan.Sku.Name, @"\d+").Value, out workerSizeAsNumber);
                AppServicePlan.Sku.Name       = string.IsNullOrWhiteSpace(WorkerSize) ? CmdletHelpers.GetSkuName(AppServicePlan.Sku.Tier, workerSizeAsNumber) : CmdletHelpers.GetSkuName(AppServicePlan.Sku.Tier, WorkerSize);
                AppServicePlan.PerSiteScaling = PerSiteScaling;
                AppServicePlan.Tags           = (IDictionary <string, string>)CmdletHelpers.ConvertToStringDictionary(Tag);
                break;
            }

            // Fix Server Farm SKU description
            AppServicePlan.Sku.Size   = AppServicePlan.Sku.Name;
            AppServicePlan.Sku.Family = AppServicePlan.Sku.Name.Substring(0, 1);

            WriteObject(new PSAppServicePlan(WebsitesClient.CreateOrUpdateAppServicePlan(ResourceGroupName, Name, AppServicePlan)), true);
        }
 protected override void ProcessRecord()
 {
     WriteObject(CmdletHelpers.GetCertificates(this.ResourcesClient, this.WebsitesClient, ResourceGroupName, Thumbprint));
 }
        public override void ExecuteCmdlet()
        {
            if (HyperV.IsPresent &&
                (Tier != "PremiumContainer" && Tier != "PremiumV3" && Tier != "IsolatedV2"))
            {
                throw new Exception("HyperV switch is only allowed for PremiumContainer ,  PremiumV3 or IsolatedV2 tiers");
            }
            if (!HyperV.IsPresent && Tier == "PremiumContainer")
            {
                throw new Exception("PremiumContainer tier is only allowed if HyperV switch is present");
            }

            if (string.IsNullOrWhiteSpace(Tier))
            {
                Tier = "Free";
            }

            if (string.IsNullOrWhiteSpace(WorkerSize))
            {
                WorkerSize = "Small";
            }

            var aseResourceGroupName = AseResourceGroupName;

            if (!string.IsNullOrEmpty(AseName) &&
                string.IsNullOrEmpty(aseResourceGroupName))
            {
                aseResourceGroupName = ResourceGroupName;
            }

            var capacity = NumberofWorkers < 1 ? 1 : NumberofWorkers;
            var skuName  = CmdletHelpers.GetSkuName(Tier, WorkerSize);

            var sku = new SkuDescription
            {
                Tier     = Tier,
                Name     = skuName,
                Capacity = capacity
            };

            var appServicePlan = new AppServicePlan
            {
                Location       = Location,
                Sku            = sku,
                PerSiteScaling = PerSiteScaling,
                IsXenon        = HyperV.IsPresent,
                Tags           = (IDictionary <string, string>)CmdletHelpers.ConvertToStringDictionary(Tag),
                Reserved       = Linux.IsPresent
            };

            AppServicePlan retPlan = null;

            if (!string.IsNullOrEmpty(AseResourceId))
            {
                retPlan = WebsitesClient.CreateOrUpdateAppServicePlan(ResourceGroupName, Name, appServicePlan, AseResourceId);
            }
            else
            {
                retPlan = WebsitesClient.CreateOrUpdateAppServicePlan(ResourceGroupName, Name, appServicePlan, AseName, aseResourceGroupName);
            }

            PSAppServicePlan psPlan = new PSAppServicePlan(retPlan);

            WriteObject(psPlan, true);
        }
        public override void ExecuteCmdlet()
        {
            if (!string.IsNullOrWhiteSpace(ResourceGroupName) && !string.IsNullOrWhiteSpace(WebAppName))
            {
                string kvId = string.Empty, kvRgName = string.Empty, kvSubscriptionId = string.Empty;
                var    webApp            = new PSSite(WebsitesClient.GetWebApp(ResourceGroupName, WebAppName, Slot));
                var    location          = webApp.Location;
                var    serverFarmId      = webApp.ServerFarmId;
                var    keyvaultResources = this.ResourcesClient.ResourceManagementClient.FilterResources(new FilterResourcesOptions
                {
                    ResourceType = "Microsoft.KeyVault/Vaults"
                }).ToArray();

                foreach (var kv in keyvaultResources)
                {
                    if (kv.Name == KeyVaultName)
                    {
                        kvId     = kv.Id;
                        kvRgName = kv.ResourceGroupName;
                        break;
                    }
                }
                if (string.IsNullOrEmpty(kvId))
                {
                    kvId = KeyVaultName;
                    if (CmdletHelpers.IsValidAKVResourceId(kvId))
                    {
                        var details = CmdletHelpers.GetResourceDetailsFromResourceId(kvId);
                        kvRgName         = details.ResourceGroupName;
                        KeyVaultName     = details.ResourceName;
                        kvSubscriptionId = details.Subscription;
                    }
                    else //default to AppService RG
                    {
                        kvRgName = ResourceGroupName;
                    }
                }
                var kvpermission = CmdletHelpers.CheckServicePrincipalPermissions(this.ResourcesClient, this.KeyvaultClient, kvRgName, KeyVaultName, kvSubscriptionId);
                var lnk          = "https://azure.github.io/AppService/2016/05/24/Deploying-Azure-Web-App-Certificate-through-Key-Vault.html";
                if (kvpermission.ToLower() != "get")
                {
                    WriteWarning("Unable to verify Key Vault permissions.");
                    WriteWarning("You may need to grant Microsoft.Azure.WebSites service principal the Secret:Get permission");
                    WriteWarning(string.Format("Find more details here: '{0}'", lnk));
                }

                Certificate kvc         = null;
                var         certificate = new Certificate(
                    location: location,
                    keyVaultId: kvId,
                    password: "",
                    keyVaultSecretName: CertName,
                    serverFarmId: serverFarmId
                    );

                if (this.ShouldProcess(this.WebAppName, string.Format($"Importing keyvault certificate for Web App '{WebAppName}'")))
                {
                    try
                    {
                        kvc = WebsitesClient.CreateCertificate(ResourceGroupName, KeyVaultName + '-' + CertName, certificate);
                    }
                    catch (DefaultErrorResponseException e)
                    {
                        if (e.Response.StatusCode != HttpStatusCode.Conflict)
                        {
                            throw e;
                        }
                    }
                }
                WriteObject(new PSCertificate(kvc));
            }
        }
Exemplo n.º 8
0
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();
            switch (ParameterSetName)
            {
            case ParameterSet1Name:
                AppServicePlan              = WebsitesClient.GetAppServicePlan(ResourceGroupName, Name);
                AppServicePlan.Sku.Tier     = string.IsNullOrWhiteSpace(Tier) ? AppServicePlan.Sku.Tier : Tier;
                AppServicePlan.Sku.Capacity = NumberofWorkers > 0 ? NumberofWorkers : AppServicePlan.Sku.Capacity;
                var workerSizeAsNumber = int.Parse(AppServicePlan.Sku.Name.Substring(1, AppServicePlan.Sku.Name.Length - 1));
                AppServicePlan.Sku.Name = string.IsNullOrWhiteSpace(WorkerSize) ? CmdletHelpers.GetSkuName(AppServicePlan.Sku.Tier, workerSizeAsNumber) : CmdletHelpers.GetSkuName(AppServicePlan.Sku.Tier, WorkerSize);
                break;
            }

            // Fix Server Farm SKU description
            AppServicePlan.Sku.Size   = AppServicePlan.Sku.Name;
            AppServicePlan.Sku.Family = AppServicePlan.Sku.Name.Substring(0, 1);

            WriteObject(WebsitesClient.CreateAppServicePlan(ResourceGroupName, Name, AppServicePlan.Location, AdminSiteName, AppServicePlan.Sku), true);
        }
        public override void ExecuteCmdlet()
        {
            if (!string.IsNullOrWhiteSpace(ResourceGroupName) && !string.IsNullOrWhiteSpace(WebAppName))
            {
                if (ShouldProcess(WebAppName, $"Removing Access Restriction Rule from Web App '{WebAppName}'"))
                {
                    var                   webApp                  = new PSSite(WebsitesClient.GetWebApp(ResourceGroupName, WebAppName, SlotName));
                    SiteConfig            siteConfig              = webApp.SiteConfig;
                    var                   accessRestrictionList   = TargetScmSite ? siteConfig.ScmIpSecurityRestrictions : siteConfig.IpSecurityRestrictions;
                    IpSecurityRestriction ipSecurityRestriction   = null;
                    bool                  accessRestrictionExists = false;

                    foreach (var accessRestriction in accessRestrictionList)
                    {
                        if (!string.IsNullOrWhiteSpace(Name))
                        {
                            if (!string.IsNullOrWhiteSpace(accessRestriction.Name) && accessRestriction.Name.ToLowerInvariant() == Name.ToLowerInvariant() && accessRestriction.Action.ToLowerInvariant() == Action.ToLowerInvariant())
                            {
                                ipSecurityRestriction   = accessRestriction;
                                accessRestrictionExists = true;
                                break;
                            }
                        }
                        else if (!string.IsNullOrWhiteSpace(IpAddress))
                        {
                            if (!string.IsNullOrWhiteSpace(accessRestriction.IpAddress) && accessRestriction.IpAddress.ToLowerInvariant() == IpAddress.ToLowerInvariant() && accessRestriction.Action.ToLowerInvariant() == Action.ToLowerInvariant())
                            {
                                if (!string.IsNullOrWhiteSpace(Name))
                                {
                                    if (!string.IsNullOrWhiteSpace(accessRestriction.Name) && accessRestriction.Name.ToLowerInvariant() == Name.ToLowerInvariant())
                                    {
                                        continue;
                                    }
                                }

                                ipSecurityRestriction   = accessRestriction;
                                accessRestrictionExists = true;
                                break;
                            }
                        }
                        else if (!string.IsNullOrWhiteSpace(ServiceTag))
                        {
                            if (!string.IsNullOrWhiteSpace(accessRestriction.IpAddress) && accessRestriction.IpAddress.ToLowerInvariant() == ServiceTag.ToLowerInvariant() && accessRestriction.Action.ToLowerInvariant() == Action.ToLowerInvariant())
                            {
                                if (!string.IsNullOrWhiteSpace(Name))
                                {
                                    if (!string.IsNullOrWhiteSpace(accessRestriction.Name) && accessRestriction.Name.ToLowerInvariant() == Name.ToLowerInvariant())
                                    {
                                        continue;
                                    }
                                }

                                ipSecurityRestriction   = accessRestriction;
                                accessRestrictionExists = true;
                                break;
                            }
                        }
                        else if (!string.IsNullOrWhiteSpace(SubnetId) || (!string.IsNullOrWhiteSpace(SubnetName) && !string.IsNullOrWhiteSpace(VirtualNetworkName)))
                        {
                            var subnet           = !string.IsNullOrWhiteSpace(SubnetId) ? SubnetId : SubnetName;
                            var subnetResourceId = CmdletHelpers.ValidateSubnet(subnet, VirtualNetworkName, ResourceGroupName, DefaultContext.Subscription.Id);
                            if (!string.IsNullOrWhiteSpace(accessRestriction.VnetSubnetResourceId) && accessRestriction.VnetSubnetResourceId.ToLowerInvariant() == subnetResourceId.ToLowerInvariant() && accessRestriction.Action.ToLowerInvariant() == Action.ToLowerInvariant())
                            {
                                if (!string.IsNullOrWhiteSpace(Name))
                                {
                                    if (!string.IsNullOrWhiteSpace(accessRestriction.Name) && accessRestriction.Name.ToLowerInvariant() == Name.ToLowerInvariant())
                                    {
                                        continue;
                                    }
                                }

                                ipSecurityRestriction   = accessRestriction;
                                accessRestrictionExists = true;
                                break;
                            }
                        }
                    }

                    if (accessRestrictionExists)
                    {
                        accessRestrictionList.Remove(ipSecurityRestriction);

                        // Update web app configuration
                        WebsitesClient.UpdateWebAppConfiguration(ResourceGroupName, webApp.Location, WebAppName, SlotName, siteConfig);
                    }

                    if (PassThru)
                    {
                        // Refresh object to get the final state
                        webApp = new PSSite(WebsitesClient.GetWebApp(ResourceGroupName, WebAppName, SlotName));
                        var accessRestrictionConfig = new PSAccessRestrictionConfig(ResourceGroupName, WebAppName, webApp.SiteConfig, SlotName);
                        WriteObject(accessRestrictionConfig);
                    }
                }
            }
        }