PowerShell Select-Object Property和ExpandProperty的差别
Posted 师万物的博客
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PowerShell Select-Object Property和ExpandProperty的差别相关的知识,希望对你有一定的参考价值。
环境配置说明
- Windows 21H1
- PSVersion 5.1.19041.1320
示例
PS C:\\Users\\admin> Get-Alias | Select-Object -Property ModuleName | Get-Member
TypeName:Selected.System.Management.Automation.AliasInfo
Name MemberType Definition
---- ---------- ----------
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
ModuleName NoteProperty string ModuleName=
PS C:\\Users\\admin> Get-Alias | Select-Object -ExpandProperty ModuleName | Get-Member
TypeName:System.String
Name MemberType Definition
---- ---------- ----------
Clone Method System.Object Clone(), System.Object ICloneable.Clone()
CompareTo Method int CompareTo(System.Object value), int CompareTo(string strB), int IC...
Contains Method bool Contains(string value)
CopyTo Method void CopyTo(int sourceIndex, char[] destination, int destinationIndex,...
EndsWith Method bool EndsWith(string value), bool EndsWith(string value, System.String...
Equals Method bool Equals(System.Object obj), bool Equals(string value), bool Equals...
GetEnumerator Method System.CharEnumerator GetEnumerator(), System.Collections.IEnumerator ...
GetHashCode Method int GetHashCode()
GetType Method type GetType()
GetTypeCode Method System.TypeCode GetTypeCode(), System.TypeCode IConvertible.GetTypeCode()
.....
- -ExpandProperty ModuleName 的返回类型是 System.String ,更适合作参数,适用范围较广
PS C:\\Users\\admin> Get-Alias | Select-Object -Property ModuleName | Select-Object -First 10
ModuleName
----------
Microsoft.PowerShell.Utility
PS C:\\Users\\admin> Get-Alias | Select-Object -ExpandProperty ModuleName | Select-Object -First 10
Microsoft.PowerShell.Utility
学习资料
感恩曾经帮助过 师万物 的人。
学有余力的话,可以了解具有开源、跨平台特性的Powershell Core。
欢迎关注公众号:悟为生心
以上是关于PowerShell Select-Object Property和ExpandProperty的差别的主要内容,如果未能解决你的问题,请参考以下文章
PowerShell Select-Object Property和ExpandProperty的差别
PowerShell Select-Object 保留排序后一定数量的首尾行
powershell use calculated properties