gpt4 book ai didi

powershell - 数组中奇怪的不存在的属性

转载 作者:行者123 更新时间:2023-12-03 16:47:15 25 4
gpt4 key购买 nike

<分区>

所以我有一个名为 $monitors 的数组。我认为它包含的内容并不重要,但它是一个 SCOM 监视器列表,由以下两行创建:

Start-OperationsManagerClientShell -ManagementServerName: "your-mgmt-server" -PersistConnection: $false -Interactive: $false;
$monitors = Get-SCOMMonitor | Where-Object -Property XmlTag -eq "UnitMonitor"

输出这个数组,它的成员似乎有两个属性叫做 Overridden 和 Target(一直向右滚动):

PS D:\Daniel> $monitors

Enabled DisplayName ParentMonitorID Overri Target
dden
------- ----------- --------------- ------ ------
true Database Performance (rollup) ManagementPackElementUniqueIdentif... True SQL Server 2005 DB Engine
true File Share Shadow Copy Availability ManagementPackElementUniqueIdentif... False File Server VSS Agent Service (Windows Serv...
true Server Role hosts User Service Category - Configuration ManagementPackElementUniqueIdentif... False Server Role
false Delt-Astraia License Monitor ManagementPackElementUniqueIdentif... False Windows Server
true DB Memory-Optimized Data Filegroup Space (rollup) ManagementPackElementUniqueIdentif... True SQL Server 2016 DB

但是根据Get-Member,“Overridden”不存在:

PS D:\Daniel> $monitors | gm


TypeName: Microsoft.EnterpriseManagement.Configuration.ManagementPackUnitMonitor

Name MemberType Definition
---- ---------- ----------
CheckVersionCompatibility Method System.Collections.Generic.IList[Microsoft.EnterpriseManagement.Configuration.Verification.ManagementPackVerificationResult] CheckVersionCompatibilit...
CreateNavigator Method System.Xml.XPath.XPathNavigator CreateNavigator(), System.Xml.XPath.XPathNavigator IXPathNavigable.CreateNavigator()
Equals Method bool Equals(System.Object obj)
GetCategories Method System.Collections.Generic.IList[Microsoft.EnterpriseManagement.Configuration.ManagementPackCategory] GetCategories()
GetDisplayString Method Microsoft.EnterpriseManagement.Configuration.ManagementPackDisplayString GetDisplayString(cultureinfo culture), Microsoft.EnterpriseManagement.Config...
GetFolders Method Microsoft.EnterpriseManagement.Configuration.ManagementPackElementCollection[Microsoft.EnterpriseManagement.Configuration.ManagementPackFolder] GetFo...
GetHashCode Method int GetHashCode()
GetImageReferences Method System.Collections.Generic.IEnumerable[Microsoft.EnterpriseManagement.Configuration.ManagementPackImageReference] GetImageReferences()
GetKnowledgeArticle Method Microsoft.EnterpriseManagement.Configuration.ManagementPackKnowledgeArticle GetKnowledgeArticle(cultureinfo culture), Microsoft.EnterpriseManagement....
GetManagementPack Method Microsoft.EnterpriseManagement.Configuration.ManagementPack GetManagementPack()
GetOverrideableParameters Method System.Collections.Generic.IList[Microsoft.EnterpriseManagement.Configuration.ManagementPackOverrideableParameter] GetOverrideableParameters()
GetType Method type GetType()
Reconnect Method void Reconnect(Microsoft.EnterpriseManagement.Configuration.ManagementPack mp), void Reconnect(Microsoft.EnterpriseManagement.EnterpriseManagementGro...
ToString Method string ToString()
Verify Method System.Collections.Generic.IList[Microsoft.EnterpriseManagement.Configuration.Verification.ManagementPackVerificationResult] Verify(Microsoft.Enterpr...
WriteXml Method void WriteXml(System.Xml.XmlWriter writer)
Accessibility Property Microsoft.EnterpriseManagement.Configuration.ManagementPackAccessibility Accessibility {get;set;}
AlertSettings Property Microsoft.EnterpriseManagement.Configuration.ManagementPackMonitorAlertSettings AlertSettings {get;set;}
Category Property Microsoft.EnterpriseManagement.Configuration.ManagementPackCategoryType Category {get;set;}
Comment Property string Comment {get;set;}
Configuration Property string Configuration {get;set;}
ConfirmDelivery Property bool ConfirmDelivery {get;set;}
Description Property string Description {get;set;}
DisplayName Property string DisplayName {get;set;}
Enabled Property Microsoft.EnterpriseManagement.Configuration.ManagementPackMonitoringLevel Enabled {get;set;}
HasNonCategoryOverride Property bool HasNonCategoryOverride {get;}
Id Property guid Id {get;}
Identifier Property Microsoft.EnterpriseManagement.Configuration.ExtensionIdentifier Identifier {get;}
InstanceName Property string InstanceName {get;set;}
LanguageCode Property string LanguageCode {get;set;}
LastModified Property datetime LastModified {get;set;}
ManagementGroup Property Microsoft.EnterpriseManagement.EnterpriseManagementGroup ManagementGroup {get;}
ManagementGroupId Property guid ManagementGroupId {get;}
Name Property string Name {get;}
OperationalStateCollection Property Microsoft.EnterpriseManagement.Configuration.ManagementPackSubElementCollection[Microsoft.EnterpriseManagement.Configuration.ManagementPackUnitMonito...
ParentMonitorID Property Microsoft.EnterpriseManagement.Configuration.ManagementPackElementReference[Microsoft.EnterpriseManagement.Configuration.ManagementPackAggregateMonit...
Priority Property Microsoft.EnterpriseManagement.Configuration.ManagementPackWorkflowPriority Priority {get;set;}
Remotable Property bool Remotable {get;set;}
RunAs Property Microsoft.EnterpriseManagement.Configuration.ManagementPackElementReference[Microsoft.EnterpriseManagement.Configuration.ManagementPackSecureReferenc...
Status Property Microsoft.EnterpriseManagement.Configuration.ManagementPackElementStatus Status {get;set;}
Target Property Microsoft.EnterpriseManagement.Configuration.ManagementPackElementReference[Microsoft.EnterpriseManagement.Configuration.ManagementPackClass] Target ...
TimeAdded Property datetime TimeAdded {get;set;}
TypeID Property Microsoft.EnterpriseManagement.Configuration.ManagementPackElementReference[Microsoft.EnterpriseManagement.Configuration.ManagementPackUnitMonitorTyp...
XmlTag Property string XmlTag {get;}

Target 属性确实存在,但如果我尝试使用 Format-Table 打印它,它会持有完全不同的值:

PS D:\Daniel> $monitors | Format-Table Target

Target
------
ManagementPackElementUniqueIdentifier=e817d034-02e8-294c-3509-01ca25481689
ManagementPackElementUniqueIdentifier=0302db52-58b0-43ff-65fe-0b492a1461ae
ManagementPackElementUniqueIdentifier=979b9385-5195-5be8-ce28-1467a6323c36
ManagementPackElementUniqueIdentifier=2d34f1de-ce5d-9a5d-bce1-67b75619d3a6

扩展属性仍然没有显示我们之前看到的值:

PS D:\Daniel> $monitors | Select-Object -ExpandProperty Target | Format-List *


Name :
Id : e817d034-02e8-294c-3509-01ca25481689
Identifier : 1|Microsoft.Windows.Library/31bf3856ad364e35|1.0.0.0|Microsoft.Windows.Server.Computer||

Name :
Id : 0302db52-58b0-43ff-65fe-0b492a1461ae
Identifier : 1|Microsoft.Windows.2016.Cluster.Management.Library/31bf3856ad364e35|1.0.0.0|Microsoft.Windows.10.0.Cluster.NetworkInterface||

Name :
Id : 979b9385-5195-5be8-ce28-1467a6323c36
Identifier : 1|Microsoft.Windows.InternetInformationServices.2000/31bf3856ad364e35|1.0.0.0|Microsoft.Windows.InternetInformationServices.2000.FTPSite||

如何访问 Target 和 Overridden 参数,以便对它们进行排序、将它们导出为 CSV 等?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com