【发布时间】:2018-02-13 17:41:09
【问题描述】:
我正在尝试获取 ip 地址和 mac 地址。下面的代码运行良好,但不适用于 windows R2,有人有什么建议吗?
主IP
(get-WmiObject Win32_NetworkAdapterConfiguration|Where {$_.Ipaddress.length -gt 1}).IPAddress | Select-object -index 0
主 MAC:
(Get-WmiObject Win32_NetworkAdapterConfiguration | where {$_.ipenabled -EQ $true}).Macaddress | select-object -first 1
【问题讨论】:
-
什么是“Windows R2”?您收到什么错误或响应?
-
它的 windows 2008 R2 企业版。我没有得到任何错误,但它根本没有返回任何值!
-
另一个例子:PS C:\Windows\system32> $disk = Get-WmiObject Win32_LogicalDisk -ComputerName 。 | Select-Object Size,FreeSpace PS C:\Windows\system32> $disk.Size PS C:\Windows\system32> $disk Size PS C:\Windows\system32> $disk Size FreeSpace ---- --------- 53684989952 5054779392 53683941376 14109630464 268432306176 21086539776 5368394173 42046615552 PS C:\Windows\system32> $disk.FreeSpace PS C:\Windows\system32>
-
您是否安装了 PowerShell v2?检查
$psversiontable。 -
通过编辑您的问题添加更多信息。读取 cmets 中的代码和错误很糟糕。
标签: powershell windows-server-2008-r2 mac-address