在powershell中检索Mac地址并将其转换为十进制格式

Mic*_*u93 2 powershell

我可以通过以下方式轻松获取PowerShell中的Mac地址:

$localMac=Get-WmiObject win32_networkadapterconfiguration | select macaddress
echo $localMac[0]
Run Code Online (Sandbox Code Playgroud)

结果是:

macaddress                                                                                                                                                   
----------                                                                                                                                                   
E8:21:32:E5:F4:6A
Run Code Online (Sandbox Code Playgroud)

如何在PowerShell中将结果更改为十进制格式?仅举例如7436378647

我试过了

$MacAddressConverted = $localMac[0] -replace '(:|-|\.)'
echo $MacAddressConverted
Run Code Online (Sandbox Code Playgroud)

它回来了

@{macaddress=E82132E5F46A}
Run Code Online (Sandbox Code Playgroud)

它接近我希望得到的但它仍然有@ {macadress =并且它没有转换为十进制

小智 5

$MAC = ((Get-WmiObject Win32_NetworkAdapterConfiguration |
        Where-Object MACAddress |
        Select-Object -ExpandProperty MACAddress -First 1
    ) -replace ':'
)
[int64]$('0x' + $MAC)
Run Code Online (Sandbox Code Playgroud)

编辑:获得更详细的版本[PSCustomObject]

Get-WmiObject win32_networkadapterconfiguration | 
    Where-Object MacAddress | ForEach {
        [PSCustomObject]@{
        'MAC_hex' = $_.MacAddress
        'MAC_dec' = [int64]("0x$($_.MacAddress.Replace(':',''))")
        'ServiceName' = $_.ServiceName
        'Description'=$_.Description}
}
Run Code Online (Sandbox Code Playgroud)

样本输出:

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
Run Code Online (Sandbox Code Playgroud)