PowerTip of the Day-Removing Empty Things
原文地址:http://app.en25.com/e/es.aspx?s=1403&e=4204&elq=c21eede5a82e4a9e99d852b591c961e5
原文:
Removing Empty Things
How do you exclude objects based on empty properties? For example, WMI returns all kinds of "network adapters:"
Get-WMIObject Win32_NetworkAdapterConfiguration
To focus only on those that have an IPAddress assigned, you should exclude any object that has an empty IPAddress property like this:
Get-WMIObject Win32_NetworkAdapterConfiguration | Where-Object { $_.IPAddress }
That's all. Where-Object will automatically convert any null-property to $false and any other to $true. That's why this line will only display processes that have a non-null company property:
Get-Process | Where-Object { $_.Company } | Select-Object Name, Company
翻译:
排除空的东西
如何把属性为空的对象排除掉?比如,WMI通过下面的语句会列出所有的网络适配器:
Get-WMIObject Win32_NetworkAdapterConfiguration
如果想只关注那些已经赋予了IP地址的适配器,就需要排除掉IP地址属性为空的所有适配器,代码如下:
Get-WMIObject Win32_NetworkAdapterConfiguration | Where-Object { $_.IPAddress }
搞定。Where-object会自动把空属性转化为$false,非空属性转化为$true。
以下代码显示进程中company属性非空的所有进程:
Get-Process | Where-Object { $_.Company } | Select-Object Name, Company
笔记:
Get,Where,Select,怎么看都像LINQ.
本文主要复习的是根据条件过滤。
---------------------------------------------------------------
aspnetx的BI笔记系列索引:
使用SQL Server Analysis Services数据挖掘的关联规则实现商品推荐功能
---------------------------------------------------------------
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步