问题:我有一个看似简单的 PowerShell 系统对象,但很难从中选择数据。有人能帮我解释一下如何选择/扩展此对象中的字段吗?
更多信息:
我已使用以下方式从 Exchange Online 环境中选择了一个对象(公共文件夹)
Get-MailPublicfolder
现在该对象存储在变量 $pf 中
$pf.getType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True ArrayList System.Object
当我这样做的时候
$pf | fl *
我得到以下输出
EmailAddressPolicyEnabled : False
PrimarySmtpAddress : [email protected]
RecipientType : PublicFolder
RecipientTypeDetails : PublicFolder
DisplayName : Metro West
等等。
但是如果我这样做
$pf.displayName
或者
$pf | select displayName
我什么也没得到
当我这样做的时候
$pf | select *
ClassId2e4f51ef21dd47e99d3c952918aff9cd : 033ecb2bc07a4d43b5ef94ed5a35d280
pageHeaderEntry :
pageFooterEntry :
autosizeInfo :
shapeInfo : Microsoft.PowerShell.Commands.Internal.Format.ListViewHeaderInfo
groupingEntry :
ClassId2e4f51ef21dd47e99d3c952918aff9cd : 9e210fe47d09416682b841769c78b8a3
shapeInfo :
groupingEntry :
ClassId2e4f51ef21dd47e99d3c952918aff9cd : 27c87ef9bbda4f709f6b4002fa4af63c
formatEntryInfo : Microsoft.PowerShell.Commands.Internal.Format.ListViewEntry
outOfBand : False
writeStream : None
ClassId2e4f51ef21dd47e99d3c952918aff9cd : 4ec4f0187cb04f4cb6973460dfe252df
groupingEntry :
ClassId2e4f51ef21dd47e99d3c952918aff9cd : cf522b78d86c486691226b40aa69e95c
groupingEntry :
和这个
$pf | gm
TypeName: Microsoft.PowerShell.Commands.Internal.Format.FormatStartData
Name MemberType Definition
---- ---------- ----------
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
autosizeInfo Property Microsoft.PowerShell.Commands.Internal.Format.AutosizeInfo, System.Managem...
ClassId2e4f51ef21dd47e99d3c952918aff9cd Property string ClassId2e4f51ef21dd47e99d3c952918aff9cd {get;}
groupingEntry Property Microsoft.PowerShell.Commands.Internal.Format.GroupingEntry, System.Manage...
pageFooterEntry Property Microsoft.PowerShell.Commands.Internal.Format.PageFooterEntry, System.Mana...
pageHeaderEntry Property Microsoft.PowerShell.Commands.Internal.Format.PageHeaderEntry, System.Mana...
shapeInfo Property Microsoft.PowerShell.Commands.Internal.Format.ShapeInfo, System.Management...
TypeName: Microsoft.PowerShell.Commands.Internal.Format.GroupStartData
Name MemberType Definition
---- ---------- ----------
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
ClassId2e4f51ef21dd47e99d3c952918aff9cd Property string ClassId2e4f51ef21dd47e99d3c952918aff9cd {get;}
groupingEntry Property Microsoft.PowerShell.Commands.Internal.Format.GroupingEntry, System.Manage...
shapeInfo Property Microsoft.PowerShell.Commands.Internal.Format.ShapeInfo, System.Management...
TypeName: Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData
Name MemberType Definition
---- ---------- ----------
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
ClassId2e4f51ef21dd47e99d3c952918aff9cd Property string ClassId2e4f51ef21dd47e99d3c952918aff9cd {get;}
formatEntryInfo Property Microsoft.PowerShell.Commands.Internal.Format.FormatEntryInfo, System.Mana...
outOfBand Property bool outOfBand {get;set;}
writeStream Property Microsoft.PowerShell.Commands.Internal.Format.WriteStreamType, System.Mana...
TypeName: Microsoft.PowerShell.Commands.Internal.Format.GroupEndData
Name MemberType Definition
---- ---------- ----------
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
ClassId2e4f51ef21dd47e99d3c952918aff9cd Property string ClassId2e4f51ef21dd47e99d3c952918aff9cd {get;}
groupingEntry Property Microsoft.PowerShell.Commands.Internal.Format.GroupingEntry, System.Manage...
TypeName: Microsoft.PowerShell.Commands.Internal.Format.FormatEndData
Name MemberType Definition
---- ---------- ----------
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
ClassId2e4f51ef21dd47e99d3c952918aff9cd Property string ClassId2e4f51ef21dd47e99d3c952918aff9cd {get;}
groupingEntry Property Microsoft.PowerShell.Commands.Internal.Format.GroupingEntry, System.Manage...
答案1
做这个:
$pf = Get-MailPublicfolder
不要这样做:
$pf = Get-MailPublicfolder | fl
# or
$pf = Get-MailPublicfolder | Format-List
为什么?当您将结果传递给 时Format-List
,您最终会得到一个格式化的字符串对象,而不是MailPublicFolder
返回的Get-MailPublicfolder
。这就是为什么您在运行 时会看到这些成员的原因gm
。
你可以通过这样做来测试,并且这个对象将具有相同的成员
$a = Get-ChildItem | Format-List
$a | Get-Member