惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

N
News and Events Feed by Topic
T
The Exploit Database - CXSecurity.com
P
Palo Alto Networks Blog
T
Threat Research - Cisco Blogs
Cloudbric
Cloudbric
Recent Commits to openclaw:main
Recent Commits to openclaw:main
I
Intezer
Attack and Defense Labs
Attack and Defense Labs
P
Privacy International News Feed
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
L
Lohrmann on Cybersecurity
C
Cybersecurity and Infrastructure Security Agency CISA
V2EX - 技术
V2EX - 技术
AWS News Blog
AWS News Blog
O
OpenAI News
L
LINUX DO - 最新话题
N
News | PayPal Newsroom
PCI Perspectives
PCI Perspectives
www.infosecurity-magazine.com
www.infosecurity-magazine.com
T
Troy Hunt's Blog
Latest news
Latest news
D
Darknet – Hacking Tools, Hacker News & Cyber Security
A
Arctic Wolf
Spread Privacy
Spread Privacy
G
GRAHAM CLULEY
T
Tor Project blog
博客园_首页
Know Your Adversary
Know Your Adversary
有赞技术团队
有赞技术团队
S
Secure Thoughts
美团技术团队
Apple Machine Learning Research
Apple Machine Learning Research
爱范儿
爱范儿
T
Tailwind CSS Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
V
Visual Studio Blog
J
Java Code Geeks
Cisco Talos Blog
Cisco Talos Blog
Schneier on Security
Schneier on Security
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
S
Security Affairs
Jina AI
Jina AI
人人都是产品经理
人人都是产品经理
雷峰网
雷峰网
宝玉的分享
宝玉的分享
量子位
Last Week in AI
Last Week in AI
月光博客
月光博客
罗磊的独立博客
S
SegmentFault 最新的问题

博客园 - Vincent Yang

Cannot load macro project error SQL Express - "Failed generate a user instance..." SQL Express 2008 x64 Integration with Visual Studio 2008 SP1 PowerShell Operators Crystal Reports .NET Error - "Access to report file denied. Another program may be using it." - Vincent Yang (转:)SharePoint Database Naming Standards List Types & List Internal ID available within MOSS 2007 Telerik: IIS7 & IIS 7.5 and ‘Telerik.Web.UI.WebResource.axd’ is missing in web config 64bit SQL Server issues : Connections to SQL Server files (*.mdf) require SQL Server Express 2005 to function properly 正式入住Windows 7 + XPM A Generic Singleton Form Provider for C# Extreme Programming: Do these 12 practices make perfect? Pick up the pace with extreme programming Testing an ASP.NET Web Service using PowerShell Parsing XML Files with PowerShell Testing SQL Stored Procedures using PowerShell Generating iCalender file using ASP.NET SQL Server Precision And Scale Problems (SQL Server 精度问题) Six Quick Crystal Reports Design Tips
Working with Collections of Objects using PowerShell
Vincent Yang · 2009-02-13 · via 博客园 - Vincent Yang

Ref: http://jamesmccaffrey.spaces.live.com/blog/cns!504C7CC53E7E7FE8!593.entry

I recently spoke at the Microsoft Management Summit. MMS is a huge event and this year had over 4,000 attendees. All four of my talks were introductory level talks about PowerShell, Microsoft’s new shell and scripting environment. Over the course of delivering training to many hundreds of people, I’ve discovered that beginners are often confused about the difference between the select-object and the where-object cmdlets. In short, if you are dealing with a collection of objects, and you think of that collection as a table with rows and columns, then select-object is used to select columns, and where-object is used to select rows. There are several exceptions that I’ll describe in a moment, but this simplification is a useful mnemonic. Consider these PowerShell commands:

(1)> $p = get-process
(2)> $p | more
(3)> $p | get-member | more
(4)> $p[0].Name
(5)> $p[0].ProcessName
(6)> $p[0].get_ProcessName()
(7)> $q = $p | select-object name,id,handles
(8)> $q
(9)> $q | format-list
(10)> $r = $q | where-object { $_.handles –gt 500 }
(11)> $r | format-list

The (1) command fetches process information into a $p array of objects. The (2) command displays the $p array as a table. Each row represents one process and each column is a property. The (3) command shows that objects can have properties, property aliases, and underlying methods. The (4),(5), and (6) commands shows how to get at the ProcessName “column” of the $p “table”. The (7) command uses select-object to conceptually select just the Name, ID, and Handles columns of the $p “table” and store into a $q object. The (8) command displays the result but illustrates that results can scroll off to the right of a PowerShell shell. The (9) command shows how to print collections of objects nicely. The (10) command uses the where-object cmdlet to select just those rows where the Handles column is greater than 500. Notice that where-object is an implied loop and so the curly brace notation is required. The $_ means “the current object in the loop.”

Now there are a few details. Confusingly, the select-object cmdlet supports –first n and –last n parameters; this means you can select rows using select-object. Also some cmdlets support parameters such as –filter, and –include which can be used to select rows. Furthermore, instead of using the implicit loop of the where-object cmdlet, you can use the explicit foreach-object cmdlet. Well, all these (and other) exceptions aside, if you remember the little rule, “select-object selects columns and where-object selects rows”, you’ll be fine in most situations.

CollectionsOfObjectsWithPS