
У меня есть скрипт 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
Выглядит как: