
PowerShell スクリプトはありますが、Excel シートのような出力グリッドを取得できないという問題があります。
コードは次のとおりです:
Get-NetFirewallRule |
Where-Object {($_.Profiles -band [Microsoft.PowerShell.Cmdletization.GeneratedTypes.NetSecurity.Profile]::Domain) -or ($_.Profiles -eq [Microsoft.PowerShell.Cmdletization.GeneratedTypes.NetSecurity.Profile]::Any)} |
ForEach-Object {
$portFilter = Get-NetFirewallPortFilter -AssociatedNetFirewallRule $_
$_ | Select-Object -Property `
Name,
DisplayName,
DisplayGroup,
Profiles,
Direction,
@{n='Protocol'; e={$portFilter.Protocol}},
@{n='LocalPort'; e={$portFilter.LocalPort}},
@{n='RemotePort'; e={$portFilter.RemotePort}},
@{n='RemoteAddress'; e={(Get-NetFirewallAddressFilter -AssociatedNetFirewallRule $_).RemoteAddress}},
Enabled,
Profile,
Action
}
出力をグリッド形式で表示し、Excel スプレッドシートのように表示するにはどうすればよいでしょうか。
答え1
| Out-GridView
最後に以下を追加します:
Get-NetFirewallRule |
Where-Object {($_.Profiles -band [Microsoft.PowerShell.Cmdletization.GeneratedTypes.NetSecurity.Profile]::Domain) -or ($_.Profiles -eq [Microsoft.PowerShell.Cmdletization.GeneratedTypes.NetSecurity.Profile]::Any)} |
ForEach-Object {
$portFilter = Get-NetFirewallPortFilter -AssociatedNetFirewallRule $_
$_ | Select-Object -Property `
Name,
DisplayName,
DisplayGroup,
Profiles,
Direction,
@{n='Protocol'; e={$portFilter.Protocol}},
@{n='LocalPort'; e={$portFilter.LocalPort}},
@{n='RemotePort'; e={$portFilter.RemotePort}},
@{n='RemoteAddress'; e={(Get-NetFirewallAddressFilter -AssociatedNetFirewallRule $_).RemoteAddress}},
Enabled,
Profile,
Action
} | Out-GridView
次のようになります: