首页 > 解决方案 > 计算要在脚本中创建 if 和 else 的网卡数量

问题描述

我需要在网卡上进行不同的设置。每一个都会有不同的配置,我遇到的问题是在脚本中识别、计数和使用。

$InternalNet = Get-NetIPAddress | ?{$_.InterfaceAlias -match "Ethernet0" - and $_.AddressFamily -match "IPV4"}
$ExternalNet = Get-NetIPAddress | ?{$_.InterfaceAlias -match "Ethernet1" - and $_.AddressFamily -match "IPV4"}
$MaxInterNet = Get-NetIPAddress | ?{$_.InterfaceAlias -match "Ethernet3" - and $_.AddressFamily -match "IPV4"}

我将拥有只有 1 个网卡的机器、带有 2 个网卡的机器和带有 3 个网卡的机器。在脚本中,我想确定我们有多少张卡片,并根据我们有多少张卡片来运行一个或另一个代码。

标签: powershellnetworking

解决方案


(Get-NetAdapter).count

将返回系统上可用的网络适配器数量。


推荐阅读