我可以通过以下方式轻松获取PowerShell中的Mac地址:
$localMac=Get-WmiObject win32_networkadapterconfiguration | select macaddress
echo $localMac[0]
结果是:
macaddress
----------
E8:21:32:E5:F4:6A
如何在powershell中将结果更改为十进制格式?仅举例如7436378647
我试过
$MacAddressConverted = $localMac[0] -replace '(:|-|\.)'
echo $MacAddressConverted
返回
@{macaddress=E82132E5F46A}
它接近我希望得到的但仍然有@ {macadress =并且它没有转换为十进制
答案 0 :(得分:5)
$MAC = ((Get-WmiObject Win32_NetworkAdapterConfiguration |
Where-Object MACAddress |
Select-Object -ExpandProperty MACAddress -First 1
) -replace ':'
)
[int64]$('0x' + $MAC)
编辑以获得更详细的[PSCustomObject]
Get-WmiObject win32_networkadapterconfiguration |
Where-Object MacAddress | ForEach {
[PSCustomObject]@{
'MAC_hex' = $_.MacAddress
'MAC_dec' = [int64]("0x$($_.MacAddress.Replace(':',''))")
'ServiceName' = $_.ServiceName
'Description'=$_.Description}
}
示例输出:
MAC_hex MAC_dec ServiceName Description
------- ------- ----------- -----------
0A:00:27:xx:xx:xx 10995770599999 VBoxNetAdp VirtualBox Host-Only Ethernet Adapter #3
00:23:54:xx:xx:xx 151749299999 rt640x64 Realtek PCIe GBE Family Controller
答案 1 :(得分:4)
Get-WmiObject Win32_NetworkAdapterConfiguration |
Where-Object { $_.MacAddress } |
ForEach-Object { [convert]::ToInt64($_.MacAddress.Replace(':', ''), 16) }
它在我的笔记本电脑上显示下一个结果:
147163166963
19938372466931