当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] PowerShell 获取 Mac 地址

作者:精品下载站 日期:2024-12-14 17:02:38 浏览:13 分类:玩电脑

PowerShell 获取 Mac 地址


在 PowerShell 中获取 mac 地址的命令是 getmac、Get-WmiObject 或 Get-CimInstance。这些命令查找本地和远程计算机上的 MAC 地址。

PowerShell 中的 Get-WmiObject cmdlet 使用 win32_networkadapterconfiguration 通过 macaddress 属性检索 MAC 地址。

PowerShell 中的 Get-CmiObject cmdlet 也用于查找 MAC 地址。此命令使用 win32_networkadapterconfiguration 来获取适配器的 MAC 地址。

在本文中,我们将讨论如何使用 PowerShell 命令查找 MAC 地址。

如何使用 PowerShell 获取 Mac 地址

使用命令行 getmac 获取适配器的 MAC 地址。

getmac

在上面的 PowerShell 脚本中,命令 getmac 检索本地计算机上适配器的 MAC 地址。

上述使用 getmac 获取 mac 地址的 PowerShell 脚本的输出是:

[玩转系统] PowerShell 获取 Mac 地址

要获取远程计算机的 MAC 地址,请将开关 \s computernamegetmac.exe 命令结合使用。

getmac /s CORP-EU-101

上面的命令将获取远程计算机上的 mac 地址。

使用 Get-WmiObject 在计算机上查找 Mac 地址

使用命令 Get-WmiObject 在 PowerShell 中获取本地和远程计算机上的 MAC 地址。此命令使用 Win32_NetworkAdapterConfiguration 类获取适配器,并使用 MacAddress 属性获取 MAC 地址。

# Get mac address on local computer
Get-WmiObject win32_networkadapterconfiguration -Filter "IPEnabled='True'" | select description, macaddress

在上面的 PowerShell 脚本中,Get-WmiObject cmdlet 使用 win32_networkadapterconfiguration 类来获取网络适配器配置。此命令使用 Filter 参数仅获取 IPEnabled =True 适配器及其 mac 地址。

上述用于检索本地计算机上的 MAC 地址的 PowerShell 脚本的输出是:

[玩转系统] PowerShell 获取 Mac 地址

要获取远程计算机网络适配器的 MAC 地址,请使用 Get-WmiObject cmdlet 及其 ComputerName 参数。

Get-WmiObject win32_networkadapterconfiguration -Filter "IPEnabled='True'" -ComputerName "CORP-EU-101" | select description, macaddress   

酷提示:如何使用 Get-ComputerInfo 在 PowerShell 中获取计算机的多个属性!

使用 PowerShell Get-CimInstance 获取 Mac 地址

您可以在本地计算机以及远程计算机上通过 PowerShell 命令 Get-CimInstance 获取 MAC 地址。此命令使用 win32_NetWorkAdapterConfiguration 类获取所有网络适配器,并使用 macaddress 属性获取 MAC 地址。

# Get mac address on local computer
 Get-CimInstance win32_networkadapterconfiguration -Filter "IPEnabled='True'" | select description, macaddress

上述 PowerShell 脚本的输出获取本地计算机上的 MAC 地址。

PS C:\> Get-CimInstance win32_networkadapterconfiguration -Filter "IPEnabled='True'" | select description, macaddress

description                                                   macaddress
-----------                                                          ----------
Intel(R) Dual Band Wireless-AC 8265       B4-B2-70-D4-A3:A3
Hyper-V Virtual Ethernet Adapter            8D-03-AB-1C-22-65:82


PS C:\>        

要获取远程计算机上的 MAC 地址,请将远程 computername 参数与 Get-CimInstance cmdlet 结合使用。

# Find the mac address on the remote computer
Get-Ciminstance win32_networkadapterconfiguration -Filter "IPEnabled='True'" -ComputerName "COPR-EU-101" | select description, macaddress     

酷提示:如何使用 PowerShell 获取 BitLocker 恢复密钥!

结论

我希望上述有关如何使用 getmac.exe、Get-WmiObject 和 Get-CmiInstance cmdlet 在 PowerShell 中获取 mac 地址的文章对您有所帮助。

您可以在 ShellGeek 主页上找到有关 PowerShell Active Directory 命令和 PowerShell 基础知识的更多主题。

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯