powershell - 如何选择名称中包含括号的 NoteProperty

标签 powershell brackets

我有 powershell 代码,可以从 SCOM 中提取组信息

$d = Get-SCOMAlert -Criteria "Id = 'ab0b795c-3564-406c-b6d5-257b8788eefb" 
$d|fl

[Microsoft.Windows.Server.LogicalDisk].文件系统:NTFS
[Microsoft.Windows.Server.LogicalDisk].压缩:False
[Microsoft.Windows.Server.LogicalDisk].大小:146780712960
[Microsoft.Windows.Server.LogicalDisk].SizeNumeric:139981
[受管理:正确
健康状态:成功
状态最后修改时间:2013 年 6 月 28 日 12:53:41 PM
是否可用:正确
可用性最后修改时间:7/2/2013 2:40:35 PM
显示名称:C:
....

我可以看到 [Microsoft.Windows.Server.LogicalDisk].FileSystem noteproperty 如果我在选择语句中使用通配符

$d | select healthstate, *filesystem, id |fl

健康状况:成功
[Microsoft.Windows.Server.LogicalDisk].文件系统:NTFS
编号:4dfb9975-5815-a950-16ff-086f5e58e8d5



但我不知道如何直接选择它

$d.[Microsoft.Windows.Server.LogicalDisk].FileSystem

请指教

这是 d$ | 的输出获取成员(member)

   TypeName: Microsoft.EnterpriseManagement.Monitoring.MonitoringObject

Name                                                                MemberType            Definition                            
----                                                                ----------            ----------                            
OnRelatedEntitiesChanged                                            Event                 System.EventHandler`1[Microsoft.Ent...
ApplyTemplate                                                       Method                System.Void ApplyTemplate(Microsoft...
BeginExecuteMonitoringTask                                          Method                System.IAsyncResult BeginExecuteMon...
Commit                                                              Method                System.Void Commit(Microsoft.Enterp...
ContainsProperty                                                    Method                bool ContainsProperty(Microsoft.Ent...
CreateNavigator                                                     Method                System.Xml.XPath.XPathNavigator Cre...
EndExecuteMonitoringTask                                            Method                System.Collections.ObjectModel.Read...
Equals                                                              Method                bool Equals(System.Object obj)        
ExecuteMonitoringTask                                               Method                System.Collections.ObjectModel.Read...
GetClasses                                                          Method                System.Collections.Generic.IList[Mi...
GetCopy                                                             Method                Microsoft.EnterpriseManagement.Comm...
GetDiscoverySources                                                 Method                System.Collections.ObjectModel.Read...
GetHashCode                                                         Method                int GetHashCode()                     
GetLeastDerivedNonAbstractClass                                     Method                Microsoft.EnterpriseManagement.Conf...
GetLeastDerivedNonAbstractMonitoringClass                           Method                Microsoft.EnterpriseManagement.Conf...
GetMaintenanceWindow                                                Method                Microsoft.EnterpriseManagement.Moni...
GetMaintenanceWindowHistory                                         Method                System.Collections.ObjectModel.Read...
GetMonitorHierarchy                                                 Method                Microsoft.EnterpriseManagement.Comm...
GetMonitoringAlertReader                                            Method                Microsoft.EnterpriseManagement.Moni...
GetMonitoringAlerts                                                 Method                System.Collections.ObjectModel.Read...
GetMonitoringAlertsCount                                            Method                int GetMonitoringAlertsCount(), int...
GetMonitoringClasses                                                Method                System.Collections.ObjectModel.Read...
GetMonitoringConsoleTasks                                           Method                System.Collections.ObjectModel.Read...
GetMonitoringDiagnostics                                            Method                System.Collections.ObjectModel.Read...
GetMonitoringDiscoveries                                            Method                System.Collections.ObjectModel.Read...
GetMonitoringEventReader                                            Method                Microsoft.EnterpriseManagement.Moni...
GetMonitoringEvents                                                 Method                System.Collections.ObjectModel.Read...
GetMonitoringLinkedReports                                          Method                System.Collections.ObjectModel.Read...
GetMonitoringPerformanceData                                        Method                System.Collections.ObjectModel.Read...
GetMonitoringPerformanceDataReader                                  Method                Microsoft.EnterpriseManagement.Moni...
GetMonitoringProperties                                             Method                System.Collections.ObjectModel.Read...
GetMonitoringPropertyValue                                          Method                System.Object GetMonitoringProperty...
GetMonitoringRecoveries                                             Method                System.Collections.ObjectModel.Read...
GetMonitoringRelationshipObjects                                    Method                System.Collections.ObjectModel.Read...
GetMonitoringRelationshipObjectsWhereSource                         Method                System.Collections.ObjectModel.Read...
GetMonitoringRelationshipObjectsWhereTarget                         Method                System.Collections.ObjectModel.Read...
GetMonitoringReports                                                Method                System.Collections.ObjectModel.Read...
GetMonitoringRules                                                  Method                System.Collections.ObjectModel.Read...
GetMonitoringStateHierarchy                                         Method                Microsoft.EnterpriseManagement.Comm...
GetMonitoringStates                                                 Method                System.Collections.Generic.IList[Mi...
GetMonitoringTaskResults                                            Method                System.Collections.ObjectModel.Read...
GetMonitoringTasks                                                  Method                System.Collections.ObjectModel.Read...
GetMonitoringViews                                                  Method                System.Collections.ObjectModel.Read...
GetMostDerivedClasses                                               Method                System.Collections.Generic.IList[Mi...
GetMostDerivedMonitoringClasses                                     Method                System.Collections.ObjectModel.Read...
GetParentMonitoringObjects                                          Method                System.Collections.ObjectModel.Read...
GetParentPartialMonitoringObjects                                   Method                System.Collections.ObjectModel.Read...
GetProperties                                                       Method                System.Collections.Generic.IList[Mi...
GetRelatedMonitoringObjects                                         Method                System.Collections.ObjectModel.Read...
GetRelatedPartialMonitoringObjects                                  Method                System.Collections.ObjectModel.Read...
GetResultantCategoryOverrides                                       Method                Microsoft.EnterpriseManagement.Conf...
GetResultantOverrides                                               Method                Microsoft.EnterpriseManagement.Conf...
GetStateHierarchy                                                   Method                Microsoft.EnterpriseManagement.Comm...
GetType                                                             Method                type GetType()                        
InsertCustomMonitoringEvent                                         Method                System.Void InsertCustomMonitoringE...
InsertCustomMonitoringEvents                                        Method                System.Void InsertCustomMonitoringE...
InsertCustomMonitoringPerformanceData                               Method                System.Void InsertCustomMonitoringP...
IsInstanceOf                                                        Method                bool IsInstanceOf(Microsoft.Enterpr...
Overwrite                                                           Method                System.Void Overwrite(Microsoft.Ent...
PopulateAccessRights                                                Method                System.Void PopulateAccessRights(Mi...
RecalculateMonitoringState                                          Method                Microsoft.EnterpriseManagement.Runt...
Reconnect                                                           Method                System.Void Reconnect(Microsoft.Ent...
ResetMonitoringState                                                Method                Microsoft.EnterpriseManagement.Runt...
ScheduleMaintenanceMode                                             Method                System.Void ScheduleMaintenanceMode...
StopMaintenanceMode                                                 Method                System.Void StopMaintenanceMode(Sys...
SubmitMonitoringTask                                                Method                System.Guid SubmitMonitoringTask(Mi...
ToString                                                            Method                string ToString()                     
TryGetProperty                                                      Method                bool TryGetProperty(Microsoft.Enter...
UpdateMaintenanceMode                                               Method                System.Void UpdateMaintenanceMode(S...
[Microsoft.Windows.Computer].PrincipalName                          NoteProperty          Microsoft.EnterpriseManagement.Comm...
[Microsoft.Windows.LogicalDevice].Description                       NoteProperty          Microsoft.EnterpriseManagement.Comm...
[Microsoft.Windows.LogicalDevice].DeviceID                          NoteProperty          Microsoft.EnterpriseManagement.Comm...
[Microsoft.Windows.LogicalDevice].Name                              NoteProperty          Microsoft.EnterpriseManagement.Comm...
[Microsoft.Windows.LogicalDisk].VolumeName                          NoteProperty          Microsoft.EnterpriseManagement.Comm...
[Microsoft.Windows.Server.LogicalDisk].Compressed                   NoteProperty          Microsoft.EnterpriseManagement.Comm...
[Microsoft.Windows.Server.LogicalDisk].DriveType                    NoteProperty          Microsoft.EnterpriseManagement.Comm...
[Microsoft.Windows.Server.LogicalDisk].FileSystem                   NoteProperty          Microsoft.EnterpriseManagement.Comm...
[Microsoft.Windows.Server.LogicalDisk].QuotasDisabled               NoteProperty          Microsoft.EnterpriseManagement.Comm...
[Microsoft.Windows.Server.LogicalDisk].Size                         NoteProperty          Microsoft.EnterpriseManagement.Comm...
[Microsoft.Windows.Server.LogicalDisk].SizeNumeric                  NoteProperty          Microsoft.EnterpriseManagement.Comm...
[Microsoft.Windows.Server.LogicalDisk].SupportsDiskQuota            NoteProperty          Microsoft.EnterpriseManagement.Comm...
[Microsoft.Windows.Server.LogicalDisk].SupportsFileBasedCompression NoteProperty          Microsoft.EnterpriseManagement.Comm...
[System.ConfigItem].AssetStatus                                     NoteProperty          Microsoft.EnterpriseManagement.Comm...
[System.ConfigItem].Notes                                           NoteProperty          Microsoft.EnterpriseManagement.Comm...
[System.ConfigItem].ObjectStatus                                    NoteProperty          Microsoft.EnterpriseManagement.Comm...
[System.Entity].DisplayName                                         NoteProperty          Microsoft.EnterpriseManagement.Comm...
Item                                                                ParameterizedProperty Microsoft.EnterpriseManagement.Comm...
AvailabilityLastModified                                            Property              System.Nullable`1[[System.DateTime,...
DisplayName                                                         Property              System.String DisplayName {get;}      
FullName                                                            Property              System.String FullName {get;}         
HasChanges                                                          Property              System.Boolean HasChanges {get;}      
HealthState                                                         Property              Microsoft.EnterpriseManagement.Conf...
Id                                                                  Property              System.Guid Id {get;set;}             
InMaintenanceMode                                                   Property              System.Boolean InMaintenanceMode {g...
IsAvailable                                                         Property              System.Boolean IsAvailable {get;}     
IsManaged                                                           Property              System.Boolean IsManaged {get;}       
IsNew                                                               Property              System.Boolean IsNew {get;}           
LastModified                                                        Property              System.DateTime LastModified {get;}   
LastModifiedBy                                                      Property              System.Nullable`1[[System.Guid, msc...
LeastDerivedNonAbstractManagementPackClassId                        Property              System.Guid LeastDerivedNonAbstract...
LeastDerivedNonAbstractMonitoringClassId                            Property              System.Guid LeastDerivedNonAbstract...
MaintenanceModeLastModified                                         Property              System.Nullable`1[[System.DateTime,...
ManagementGroup                                                     Property              Microsoft.EnterpriseManagement.Mana...
ManagementGroupId                                                   Property              System.Guid ManagementGroupId {get;}  
ManagementPackClassIds                                              Property              System.Collections.Generic.IList`1[...
MonitoringClassIds                                                  Property              System.Collections.ObjectModel.Read...
Name                                                                Property              System.String Name {get;}             
Path                                                                Property              System.String Path {get;}             
StateLastModified                                                   Property              System.Nullable`1[[System.DateTime,...
TimeAdded                                                           Property              System.DateTime TimeAdded {get;}      
Values                                                              Property              System.Collections.Generic.IList`1[...

最佳答案

几种方法。您可以将属性名称包装在字符串中:

$d.'[Microsoft.Windows.Server.LogicalDisk].FileSystem'

或者,您可以将属性名称保存到变量中:

$propertyName = '[Microsoft.Windows.Server.LogicalDisk].FileSystem'
$d.$propertyName

关于powershell - 如何选择名称中包含括号的 NoteProperty,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17432657/

相关文章:

powershell - 相当于 Powershell 中的 "&& cd $_"

javascript - 解析包含括号的 jQuery 元素的函数

php - 正则表达式不在括号中

c++ - 重载括号运算符作为成员函数

regex - 获取括号内的多个值

PowerShell - 分布式解决方案

PowerShell Out-GridView 处理 Click/DoubleClik 事件

python - 从 Python 中的 Flask 路由调用 Linux Powershell 中的 .ps1 脚本

powershell - 从后台作业获取输出

sql-server - SQL Server 中用于别名的方括号和单引号有什么区别?