Azure Powershell 中多个应用服务的访问限制 AddIP

穆罕默德·伊斯梅尔

我有一个 Azure powershell 脚本,用户必须在其中添加应用服务名称、IP 地址等。我有 4 个网络应用程序,我想向其中添加相同的 IP 地址。我想对应用程序服务名称进行硬编码,以便用户不必输入它。我怎样才能在powershell中实现这一点?这是我的代码:

    Param
(
# Name of the resource group that contains the App Service.
[Parameter(Mandatory=$true)]
$RGName,

# Name of your Web or API App.
[Parameter(Mandatory=$true)]
$WebAppName,

# priority value.
[Parameter(Mandatory=$true)]
$priority,

# WhitelistIp values.
[Parameter(Mandatory=$true)]
$IPList,

# rule to add.
[PSCustomObject]$rule


)
function Add-AzureIpRestrictionRule
{
$ApiVersions = Get-AzureRmResourceProvider -ProviderNamespace Microsoft.Web | 
Select-Object -ExpandProperty ResourceTypes |
Where-Object ResourceTypeName -eq 'sites' |
Select-Object -ExpandProperty ApiVersions

$LatestApiVersion = $ApiVersions[0]

$WebAppConfig = Get-AzureRmResource -ResourceType 'Microsoft.Web/sites/config' -ResourceName $WebAppName -ResourceGroupName $RGName -ApiVersion $LatestApiVersion

$WebAppConfig.Properties.ipSecurityRestrictions = $WebAppConfig.Properties.ipSecurityRestrictions + @($rule) | 
Group-Object name | 
ForEach-Object { $_.Group | Select-Object -Last 1 }

Set-AzureRmResource -ResourceId $WebAppConfig.ResourceId -Properties $WebAppConfig.Properties -ApiVersion $LatestApiVersion -Force 
}
$IPList= @($IPList-split ",")
Write-Host "IPList found "$IPList"."
$increment = 1
foreach ($element in $IPList)
{
if ($element -eq "" -OR $element -eq " ") {continue}
else
{
$element=$element.Trim()
$rule = [PSCustomObject]@{
ipAddress = "$($element)/32"
action = "Allow"
priority = "$priority"
name = "WhitelistIP"+ $increment}
$increment++
Add-AzureIpRestrictionRule -ResourceGroupName "$RGName" -AppServiceName "$WebAppName" -rule $rule
}
}
$OutboundIP = @(Get-AzureRmWebApp -Name "$WebAppName" -ResourceGroupName "$RGName").possibleOutboundIPAddresses -split ","
$increment = 1
foreach ($element in $OutboundIP)
{
$rule = [PSCustomObject]@{
ipAddress = "$($element)/32"
action = "Allow"
priority = "$priority"
name = "OutboundIP"+ $increment}
$increment++
Add-AzureIpRestrictionRule -ResourceGroupName "$RGName" -AppServiceName "$WebAppName" -rule $rule
}

所以我$WebAppName希望它是硬编码的,但是我有 4 个这样的网络应用程序,如何让这个脚本运行 4 次,只需让用户输入他的 IP 地址一次,所有变量保持不变,只是$WebAppName应该更改为我给出的硬编码值

点头

你可以像下面这样(如果我正确理解了这个问题)。

$webAppNames = 'a,b,c,d'
$webAppList = $webAppNames.split(',')
Foreach($webAppName in $webAppList) { ....do stuff }

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何通过Powershell添加Azure应用服务扩展?

在 Azure 移动应用服务中添加多个 api

如果 Azure 应用服务实例失败,如何触发 PowerShell 脚本

如何在运行Linux的Azure应用服务上运行PowerShell脚本?

使用 Powershell 将 Azure Key Vault 证书导入应用服务?

Azure应用服务中的地理复制

Azure 应用服务中的硬件配置

从PowerShell中的Azure函数访问Azure表

单个 Azure 应用服务中的多个 asp.net 应用

通配符 SSL 映射多个 Azure 应用服务应用

在 Azure 应用服务中访问 linux 容器内的日志文件

如何防止直接访问Azure应用服务中托管的API

无法在 azure 应用服务中访问 keycloak 控制台 - 脚本 ssl 错误

使用 terraform 在 Azure 上为应用服务添加多个 IP 限制时的动态优先级更改

无法使用Facebook访问令牌登录Azure应用服务

监控 Azure 应用服务

Azure应用服务ApiApp

Azure SQL服务器集允许在ARM模板或PowerShell中访问Azure服务

Azure应用服务与Azure Service Fabric

DevOps 管道中的 Azure 应用服务问题

在 Azure 应用服务性能测试中通过 JWT

唤醒时 Azure 应用服务中的瓶颈

在 Azure 应用服务中运行 grunt 命令

如何在Azure应用服务中运行.EXE

在Terraform Azure应用服务资源中配置CORS

在 azure 应用服务中记录 Stackoverflow 异常

在Azure应用服务中从SocialLoginProvider覆盖CreateCredentials

Powershell中的Azure API SharedKeyLite

Azure PowerShell中的CD失败