Powershell
如何從 Powershell System.Object 中選擇欄位 - Exchange Online PowerShell
問:我有一個明顯簡單的 PowerShell 系統對象,我很難從中選擇數據。有人可以幫助解釋我如何選擇/擴展此對像中的欄位嗎?
更多資訊:
我已使用 Exchange Online 環境從我的 Exchange Online 環境中選擇了一個對象(公共文件夾)
Get-MailPublicfolder
現在對象儲存在變數 $pf
$pf.getType() IsPublic IsSerial Name BaseType -------- -------- ---- -------- True True ArrayList System.Object
當我這樣做時
$pf | fl *
我得到以下輸出
EmailAddressPolicyEnabled : False PrimarySmtpAddress : metrowest@company.com 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...
做這個:
$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