我的资源组中有一个虚拟网络,其默认子网已分配给虚拟网络的默认子网,但现在我想使用PowerShell添加另一个具有默认子网的多服务端点
下面的代码是我用来将服务端点Microsoft.ServiceBus添加到同一个虚拟网络中的代码。
#Get vnet
$virtualnetwork = Get-AzureRmVirtualNetwork -Name $VN -ResourceGroupName $RG
#Configure service endpoint
Add-AzureRmVirtualNetworkSubnetConfig -Name $SN -AddressPrefix $SAP -
VirtualNetwork $virtualnetwork -ServiceEndpoint $EP
#Set configuration
$virtualnetwork | Set-AzureRmVirtualNetwork 问题是,每次运行上述脚本时,它都会更新当前服务端点,而不是添加新的服务端点。任何想法
发布于 2022-10-16 16:29:33
我尝试在我的环境中复制相同的内容,并成功地添加了服务端点,如下所示.
我已经创建了带有默认子网的microsoft.storage服务端点,如下所示。

我尝试使用下面的powershell脚本将另一个服务端点Microsoft.ServiceBus添加到同一个具有默认子网的虚拟网络中。
$subscription = "ID"
$subnets = @('default')
$vnetName = "your vnetname"
$vnetRgName = "Rgname"
$newEndpoint = "Microsoft.ServiceBus"
Set-AzContext -Subscription $subscription
foreach($snet in $subnets){
Write-Host "Modifying Service Endpoints for subnet: $snet" -fore red -back white
$virtualNetwork = Get-AzVirtualNetwork -Name $vnetName -ResourceGroupName $vnetRgName | Get-AzVirtualNetworkSubnetConfig -Name $snet
$addrPrefix = $virtualNetwork.AddressPrefix
#Get existing service endpoints
$ServiceEndPoint = New-Object 'System.Collections.Generic.List[String]'
$virtualNetwork.ServiceEndpoints | ForEach-Object { $ServiceEndPoint.Add($_.service) }
if ($ServiceEndPoint -notcontains $newEndPoint){
$ServiceEndPoint.Add($newEndpoint)
}
$delegation=$virtualNetwork.Delegations
#Add new service endpoint
Get-AzVirtualNetwork -Name $vnetName -ResourceGroupName $vnetRgName | Set-AzVirtualNetworkSubnetConfig -Name $snet -AddressPrefix $addrPrefix -ServiceEndpoint $ServiceEndPoint -Delegation $delegation | Set-AzVirtualNetwork
}

输出:


要签入门户,可以成功地添加Microsoft.serviceBus和默认子网以及Microsoft.storage.。

https://stackoverflow.com/questions/74087273
复制相似问题