PowerTip of the Day-Check for a Battery
原文地址:http://app.en25.com/e/es.aspx?s=1403&e=5231&elq=4427f8ad0f9245da87fb793497c0753a
原文:
If your script needs to know whether your computer has a battery, you can ask WMI. Here is a small function:
function Has-Battery {
@(Get-WmiObject Win32_Battery).Count -ne 0
if (@(Get-WmiObject Win32_Battery).Count -ne 0) {
$true
} else {
$false
}
}
Note the use of @() which wraps the result into an array so you can check the number of batteries. Most systems have only one, but there are some systems with more.
翻译:
如果你的代码需要知道在你的机器上是否有电池,可以靠WMI。下面小函数可以实现这个方法:
function Has-Battery {
@(Get-WmiObject Win32_Battery).Count -ne 0
if (@(Get-WmiObject Win32_Battery).Count -ne 0) {
$true
} else {
$false
}
}
需要主意的是@()把结果放到一个序列中所以可以检索到多电池的情况。大多数系统都只有一个,但也有一部分系统有多个电池。
笔记:
复习WMI。
@()的说道。
---------------------------------------------------------------
aspnetx的BI笔记系列索引:
使用SQL Server Analysis Services数据挖掘的关联规则实现商品推荐功能
---------------------------------------------------------------