我的powershell代码太慢了,无法从系统主题中删除所有事件订阅。
# Get all event subscription names associated with the system topic
$subscriptions = az eventgrid system-topic event-subscription list --system-topic-name $systemTopicName --resource-group $resourceGroupName --query "[].name" -o tsv
# Iterate through each subscription and delete it
foreach ($sub in $subscriptions) {
Write-Host "Deleting event subscription: $sub"
az eventgrid system-topic event-subscription delete --system-topic-name $systemTopicName --resource-group $resourceGroupName --name $sub --yes
}
有没有更快的方法来删除所有事件订阅?
ForEach-Object -Parallel 可从 Powershell v7.0 获取,可用于并行化工作。
尝试这样的事情(未经测试):
# Get all event subscription names associated with the system topic
$subscriptions = az eventgrid system-topic event-subscription list --system-topic-name $systemTopicName --resource-group $resourceGroupName --query "[].name" -o tsv
# Iterate through each subscription and delete it
$subscriptions | Foreach-Object -Parallel {
Write-Host "Deleting event subscription: $sub"
az eventgrid system-topic event-subscription delete \
--system-topic-name $systemTopicName \
--resource-group $resourceGroupName \
--name $_ \
--yes
} -ThrottleLimit 5 # ThrottleLimit parameter limits the number of parallel scripts
请参阅 ForEach-Object 了解更多详细信息和示例。