【发布时间】:2017-12-14 00:57:40
【问题描述】:
我在 Powershell 中工作,一些查询的结果返回一个像这样的集合成员(请注意,这是从实际输出中缩短的):
SmsProviderObjectPath : SMS_SCI_SysResUse.FileType=2,ItemName="[\"Display=\\\\SERVER1.MYDOMAIN.ORG\\\"]MSWNET:[\"SMS_SITE=MBC\"]\\\\SERVER1.MYDOMAIN.ORG\\,SMS Distribution Point",ItemType="System
Resource Usage",SiteCode="MBC"
FileType : 2
ItemName : ["Display=\\SERVER1.MYDOMAIN.ORG\"]MSWNET:["SMS_SITE=MBC"]\\SERVER1.MYDOMAIN.ORG\,SMS Distribution Point
ItemType : System Resource Usage
NALPath : ["Display=\\SERVER1.MYDOMAIN.ORG\"]MSWNET:["SMS_SITE=MBC"]\\SERVER1.MYDOMAIN.ORG\
NALType : Windows NT Server
NetworkOSPath : \\SERVER1.MYDOMAIN.ORG
PropLists : {BindExcept, Protected Boundary, SourceDistributionPoints, SourceDPRanks...}
Props : {BITS download, Server Remote Name, PreStagingAllowed, SslState...}
RoleCount : 2
RoleName : SMS Distribution Point
SiteCode : MBC
SslState : 0
Type : 8
PSComputerName : prim-serv.MYDOMAIN.org
PSShowComputerName : False
ManagedObject : \\prim-serv\root\sms\site_MBC:SMS_SCI_SysResUse.FileType=2,ItemName="[\"Display=\\\\SERVER1.MYDOMAIN.ORG\\\"]MSWNET:[\"SMS_SITE=MBC\"]\\\\SERVER1.MYDOMAIN.ORG\\,SMS
Distribution Point",ItemType="System Resource Usage",SiteCode="MBC"
OverridingObjectClass : SMS_SCI_SysResUse
RegMultiStringLists : {}
SecurityVerbs : -1
ObjectClass : SMS_SCI_SysResUse
Properties :
instance of SMS_EmbeddedProperty
{
PropertyName = "IsPXE";
Value = 0;
Value1 = "";
Value2 = "";
},
instance of SMS_EmbeddedProperty
{
PropertyName = "IsActive";
Value = 0;
Value1 = "";
Value2 = "";
},
instance of SMS_EmbeddedProperty
{
PropertyName = "IsPullDP";
Value = 0;
Value1 = "";
Value2 = "";
},
instance of SMS_EmbeddedProperty
{
PropertyName = "IsMulticast";
Value = 0;
Value1 = "";
Value2 = "";
},
instance of SMS_EmbeddedProperty
{
PropertyName = "LastIISConfigCheckTime";
Value = 1490896883;
Value1 = "";
Value2 = "";
}};
RoleCount = 2;
RoleName = "SMS Distribution Point";
SiteCode = "MBC";
SslState = 0;
Type = 8;
};
PropertyNames : {FileType, ItemName, ItemType, NALPath...}
MethodNames :
MethodList : {}
PropertyList : {[FileType, 2], [ItemName, ["Display=\\SERVER1.MYDOMAIN.ORG\"]MSWNET:["SMS_SITE=MBC"]\\SERVER1.MYDOMAIN.ORG\,SMS Distribution Point], [ItemType, System Resource Usage],
[NALPath, ["Display=\\SERVER1.MYDOMAIN.ORG\"]MSWNET:["SMS_SITE=MBC"]\\SERVER1.MYDOMAIN.ORG\]...}
UniqueIdentifier : 16242167-3aac-4b79-ad5b-2c8030922ba5
ParentResultObject :
GlobalDisplayString :
AutoCommit : False
AutoRefresh : False
UserDataObject :
ConnectionManager : Microsoft.ConfigurationManagement.PowerShell.Provider.CmdletWqlConnectionManager
TraceProperties : True
NamedValueDictionary : {[AllProviderLocations, System.Collections.Generic.List`1[System.Management.ManagementBaseObject]], [ProviderLocation,
\\prim-serv\ROOT\sms:SMS_ProviderLocation.Machine="prim-serv.MYDOMAIN.org",SiteCode="MBC"], [ProviderMachineName, prim-serv.MYDOMAIN.org], [Connection,
\\prim-serv.MYDOMAIN.org\root\sms\site_MBC]...}
AsyncOperationData :
RetainObjectLock : False
我可以使用如下代码访问许多列出的项目,例如“NetworkOSPath”和“RoleName”:
$myDP = $DP.NetworkOSPath
我不知道如何引用属性区域中列出的项目,例如:
IsPXE、IsPullDP 以及与它们关联的值。
我可以使用以下命令获取它们的列表:$dp.EmbeddedProperties |格式列表 *
这会产生一个键和值列表:
Key : AllowInternetClients
Value :
instance of SMS_EmbeddedProperty
{
PropertyName = "AllowInternetClients";
Value = 0;
Value1 = "";
Value2 = "";
};
Key : BITS download
Value :
instance of SMS_EmbeddedProperty
{
PropertyName = "BITS download";
Value = 1;
Value1 = "";
Value2 = "";
};
为了只列出一个特定的键,我尝试了以下方法但没有成功:
foreach ($DP in $DPList) {$DP.EmbeddedProperties | select-object -expandproperty IsPXE }
foreach ($DP in $DPList) {$DP.EmbeddedProperties | Select-Object where Name = "IsPXE"}
foreach ($DP in $DPList) {$DP.EmbeddedProperties | Select-Object IsPXE}
有没有办法引用键及其关联值,以便我可以将它们分配给脚本内的变量?
【问题讨论】:
-
看起来
$DP和$DP.Properties都是实现IResultObjectinterface 的对象,而后者包含SMS_EmbeddedProperty实例。您可以运行$DP.Properties.GetType()来查看该属性的运行时类型吗?你试过$DP.Properties['IsPXE']或$DP.Properties | ? PropertyName -eq 'IsPXE'吗?另外,在你上次的 sn-p 中,你为什么使用EmbeddedProperties而不是Properties?
标签: powershell