gpt4 book ai didi

azure - Remove-AzureRmRouteConfig 不能像 Get-AzureRmRouteConfig 那样与 where-object 一起使用

转载 作者:行者123 更新时间:2023-12-03 02:57:18 25 4
gpt4 key购买 nike

Get-AzureRmRouteConfig -RouteTable $rt | Where-Object {$_.Name -like "*virginia*"}

获取具有预期名称的所有路由配置。例如,usgovvirginia_1

Remove-AzureRmRouteConfig -RouteTable $rt | Where-Object {$_.Name -like "*virginia*"}

出现此错误

Remove-AzureRmRouteConfig : Sequence contains no matching element
At line:1 char:1
+ Remove-AzureRmRouteConfig -RouteTable $rt | Where-Object {$_.Name -li ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [Remove-AzureRmRouteConfig], InvalidOperationException
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.Network.RemoveAzureRmRouteConfigCommand

我一直在尝试通过 PowerShell 使用路由表,所以我想了解为什么这不起作用

最佳答案

它不起作用的原因是因为管道从左到右工作,即从左侧输入命令的输出到右侧的下一个命令。

就您而言,您尝试在选择路线之前将其删除。

尝试类似下面的代码(另请注意最后的 Set-AzureRmRouteTable,因为除非最后执行 Set 命令,否则您的更改不会应用)

$rt = Get-AzureRmRouteTable -ResourceGroupName "your route table - resource group name"

Get-AzureRmRouteConfig -RouteTable $rt | where-object {$_.Name -like "*virginia*"} | ForEach-Object
{Remove-AzureRmRouteConfig -RouteTable $rt -Name $_.Name | Set-AzureRmRouteTable}

您也可以查看 Microsoft 文档上的示例 - https://learn.microsoft.com/en-us/powershell/module/azurerm.network/remove-azurermrouteconfig?view=azurermps-6.7.0

在第一个命令中,您首先获取路由,然后选择与路由顶部的模式/应用过滤器匹配的特定路由,以便其正常工作。

Get-AzureRmRouteConfig -RouteTable $rt | Where-Object {$_.Name -like "*virginia*"}

在第二个命令中,您尝试先删除路由,然后选择与顶部的模式/应用过滤器匹配的特定路由,因此失败

Remove-AzureRmRouteConfig -RouteTable $rt | Where-Object {$_.Name -like "*virginia*"}

关于azure - Remove-AzureRmRouteConfig 不能像 Get-AzureRmRouteConfig 那样与 where-object 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51863228/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com