簡體   English   中英

Azure NSG 規則暴露給 inte.net

[英]Azure NSG rules exposed to internet

我正在創建一個 PS 腳本,它獲取 Azure NSG 中允許訪問 inte.net 的所有端口,這里的問題是我想在下面的腳本中通過端口號獲取我只能獲取一個端口但如何獲取多個端口.

目前我正在獲取 443,同時我想獲取 80 和 8443,我可以在下面的腳本的 -eq 條件下編寫邏輯嗎

$subscriptions = 'xxxxxxx'
foreach ($azsub in $subscriptions)
{
set-AzContext -subscription $azsub
$aznsgs = Get-AzNetworksecuritygroup
 foreach ($aznsg in $aznsgs)
  { 
    Get-Aznetworksecurityruleconfig -networksecuritygroup $aznsg | Where-Object { $_.DestinationPortRange -eq "443"  | Select-object `
                   @{label = 'NSG name'   ; expression = {$aznsg.name}}, ` 
                   @{label = 'Rulename'   ; expression = {$_.name}} , `
                   @{label = 'Port Range' ; expression = {$_.destinationportrange}} , 'access' , 'priority' , 'direction', `
                   @{label = 'RG name'    ; expression = {$aznsg.resourcegroupname}`
         } | Export-Csv -path "C:\Users\xxxx\Documents\NSG.CSV" -NoTypeInformation -Append
   }
}

您可以在 where 中執行多個條件。
這是一個類似的帖子Where-object $_ matches multiple criteria

帖子中的示例

data | Where-Object{
  $_.Name -eq "$serverName.chrobinson.com" -and (
     $_.Description1 -match "bnx2x" -or
     $_.Description1 -match "be2net"
  )
} | Select-Object -expand version

只需更新您的 where 子句以包含所有這些子句。

Where-Object { ($_.DestinationPortRange -eq "443" -or $_.DestinationPortRange -eq "80" -or $_.DestinationPortRange -eq "8443")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM