如何从powershell中的GET-timezone函数响应中读取时区id

如何从powershell中的GET-timezone函数响应中读取时区id,powershell,timezone,Powershell,Timezone,我是powershell新手,因此不知道从powershell中的GET-timezone函数响应中读取时区id的最佳方法是什么 函数以这种格式返回响应 我想读取Id值。在本例中,这是印度标准时间 有什么线索吗?根据这里的要求,我的评论作为答案 cmdlet返回当前时区或可用时区列表。不使用参数,它返回本地计算机的时区 返回值总是对象,其属性如OPs屏幕截图所示。 如果只需要其中一个属性的值。您可以使用点语法 (Get-TimeZone).Id 由于括号的缘故,PowerShell会首先执行

我是powershell新手,因此不知道从powershell中的
GET-timezone
函数响应中读取时区id的最佳方法是什么

函数以这种格式返回响应

我想读取
Id
值。在本例中,这是印度标准时间

有什么线索吗?

根据这里的要求,我的评论作为答案

cmdlet返回当前时区或可用时区列表。不使用参数,它返回本地计算机的时区

返回值总是对象,其属性如OPs屏幕截图所示。
如果只需要其中一个属性的值。您可以使用点语法

(Get-TimeZone).Id
由于括号的缘故,PowerShell会首先执行cmdlet,然后从返回的对象中选择适当的属性以获取其值

另一种方法是使用
Select Object
并展开所需的属性,以便仅按如下方式接收值:

Get-TimeZone | Select-Object -ExpandProperty Id
如果没有参数
-ExpandProperty
,这将返回一个新的对象,其中一个属性名为
Id

除属性外,对象通常还有方法。要显示这些内容,可以通过管道将结果传递到另一个名为
Get Member
(简称
gm
)的cmdlet

导致

Name                       MemberType Definition                                                                                                
----                       ---------- ----------                                                                                                
Equals                     Method     bool Equals(System.TimeZoneInfo other), bool Equals(System.Object obj), bool IEquatable[TimeZoneInfo].E...
GetAdjustmentRules         Method     System.TimeZoneInfo+AdjustmentRule[] GetAdjustmentRules()                                                 
GetAmbiguousTimeOffsets    Method     timespan[] GetAmbiguousTimeOffsets(System.DateTimeOffset dateTimeOffset), timespan[] GetAmbiguousTimeOf...
GetHashCode                Method     int GetHashCode()                                                                                         
GetObjectData              Method     void ISerializable.GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Se...
GetType                    Method     type GetType()                                                                                            
GetUtcOffset               Method     timespan GetUtcOffset(System.DateTimeOffset dateTimeOffset), timespan GetUtcOffset(datetime dateTime)     
HasSameRules               Method     bool HasSameRules(System.TimeZoneInfo other)                                                              
IsAmbiguousTime            Method     bool IsAmbiguousTime(System.DateTimeOffset dateTimeOffset), bool IsAmbiguousTime(datetime dateTime)       
IsDaylightSavingTime       Method     bool IsDaylightSavingTime(System.DateTimeOffset dateTimeOffset), bool IsDaylightSavingTime(datetime dat...
IsInvalidTime              Method     bool IsInvalidTime(datetime dateTime)                                                                     
OnDeserialization          Method     void IDeserializationCallback.OnDeserialization(System.Object sender)                                     
ToSerializedString         Method     string ToSerializedString()                                                                               
ToString                   Method     string ToString()                                                                                         
BaseUtcOffset              Property   timespan BaseUtcOffset {get;}                                                                             
DaylightName               Property   string DaylightName {get;}                                                                                
DisplayName                Property   string DisplayName {get;}                                                                                 
Id                         Property   string Id {get;}                                                                                          
StandardName               Property   string StandardName {get;}                                                                                
SupportsDaylightSavingTime Property   bool SupportsDaylightSavingTime {get;}

只需将cmdlet放在括号中,并使用点添加所需的属性
(获取时区).Id
,或使用
获取时区|选择对象-ExpandProperty Id
@Theo-非常感谢!!不客气@西奥-你可以把它作为一个答案吗?@MattJohnson Pint你是对的,最好是通过发布一个答案来回答,而不是在评论中这样做。我有时觉得这太琐碎了,无法发布,但这意味着还有另一个问题“未回答”。现在发布。
Name                       MemberType Definition                                                                                                
----                       ---------- ----------                                                                                                
Equals                     Method     bool Equals(System.TimeZoneInfo other), bool Equals(System.Object obj), bool IEquatable[TimeZoneInfo].E...
GetAdjustmentRules         Method     System.TimeZoneInfo+AdjustmentRule[] GetAdjustmentRules()                                                 
GetAmbiguousTimeOffsets    Method     timespan[] GetAmbiguousTimeOffsets(System.DateTimeOffset dateTimeOffset), timespan[] GetAmbiguousTimeOf...
GetHashCode                Method     int GetHashCode()                                                                                         
GetObjectData              Method     void ISerializable.GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Se...
GetType                    Method     type GetType()                                                                                            
GetUtcOffset               Method     timespan GetUtcOffset(System.DateTimeOffset dateTimeOffset), timespan GetUtcOffset(datetime dateTime)     
HasSameRules               Method     bool HasSameRules(System.TimeZoneInfo other)                                                              
IsAmbiguousTime            Method     bool IsAmbiguousTime(System.DateTimeOffset dateTimeOffset), bool IsAmbiguousTime(datetime dateTime)       
IsDaylightSavingTime       Method     bool IsDaylightSavingTime(System.DateTimeOffset dateTimeOffset), bool IsDaylightSavingTime(datetime dat...
IsInvalidTime              Method     bool IsInvalidTime(datetime dateTime)                                                                     
OnDeserialization          Method     void IDeserializationCallback.OnDeserialization(System.Object sender)                                     
ToSerializedString         Method     string ToSerializedString()                                                                               
ToString                   Method     string ToString()                                                                                         
BaseUtcOffset              Property   timespan BaseUtcOffset {get;}                                                                             
DaylightName               Property   string DaylightName {get;}                                                                                
DisplayName                Property   string DisplayName {get;}                                                                                 
Id                         Property   string Id {get;}                                                                                          
StandardName               Property   string StandardName {get;}                                                                                
SupportsDaylightSavingTime Property   bool SupportsDaylightSavingTime {get;}