powershell - 计算要在脚本中创建 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 个网卡的机器。在脚本中,我想确定我们有多少张卡片,并根据我们有多少张卡片来运行一个或另一个代码。
解决方案
(Get-NetAdapter).count
将返回系统上可用的网络适配器数量。
推荐阅读
- vue.js - 如何 v-for 循环数据,但根据模型的输入显示它
- node.js - 在 Google Cloud Functions 中写入文件后找不到文件
- javascript - 需要在 OnClientClick 之前执行 OnClick 事件
- java - 模拟辅助方法的返回值
- php - 无法在主机上连接我的数据库
- php - 给定一个复杂的 PHP 对象层次结构,我可以确定表示属性路径的字符串是否存在?
- javascript - 如何在 reactjs 中使用引导弹出框
- leaflet - 我可以在传单 geoJSON 中动态更改 features.properties.{some property name} 中的属性吗
- android - RecyclerView 对话框中的图像
- android - FirebaseListAdapter 空视图