Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell访问嵌入式属性_Powershell - Fatal编程技术网

Powershell访问嵌入式属性

Powershell访问嵌入式属性,powershell,Powershell,我在Powershell中工作,一些查询的结果返回一个集合成员,如下所示。注意,这是从实际输出中缩短的: SmsProviderObjectPath : SMS_SCI_SysResUse.FileType=2,ItemName="[\"Display=\\\\SERVER1.MYDOMAIN.ORG\\\"]MSWNET:[\"SMS_SITE=MBC\"]\\\\SERVER1.MYDOMAIN.ORG\\,SMS Distribution Point",ItemType="System

我在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 | format list获得它们的列表*

这将生成键和值的列表:

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.EmbeddedProperties | format list*的内容添加到$dp时是否用引号括起来?使脚本的前几部分不会将文本转储到对象中。尽可能多地保留对象

在处理这样的输出时,我遇到了这样的问题

get-adgroupmember -identity $name | select stuff
直到我换了一个更好的方法

(get-adgroupmember -identity $name).stuff

看起来属性部分只是文本。$dp.EmbeddedProperties | format list*的内容添加到$dp时是否用引号括起来?使脚本的前几部分不会将文本转储到对象中。尽可能多地保留对象

在处理这样的输出时,我遇到了这样的问题

get-adgroupmember -identity $name | select stuff
直到我换了一个更好的方法

(get-adgroupmember -identity $name).stuff
您与$dp.EmbeddedProperties关系密切。只要继续打点,你就会到达那里。一旦获得要查找的值,就可以将其添加到对象中。下面是一个例子:

$dp = Get-CMDistributionPoint
$NewObj = @()
ForEach ($d in $dp)
{
    $ServerName = $d.NetworkOSPath
    $IsPXE = $d.embeddedproperties.IsPXE.Value
    $NewObj += [pscustomObject]@{ ServerName = $ServerName; IsPXE = $IsPXE }
}
$NewObj | Out-GridView
小心-一旦你通过EmbeddedProperties,你就进入了区分大小写的怪诞世界!如果你没有正确的答案,你将一无所获!我不知道为什么。也许它与.NET的System.Collections.Generic.Dictionary类和区分大小写的字符串键有关? 即

您与$dp.EmbeddedProperties关系密切。只要继续打点,你就会到达那里。一旦获得要查找的值,就可以将其添加到对象中。下面是一个例子:

$dp = Get-CMDistributionPoint
$NewObj = @()
ForEach ($d in $dp)
{
    $ServerName = $d.NetworkOSPath
    $IsPXE = $d.embeddedproperties.IsPXE.Value
    $NewObj += [pscustomObject]@{ ServerName = $ServerName; IsPXE = $IsPXE }
}
$NewObj | Out-GridView
小心-一旦你通过EmbeddedProperties,你就进入了区分大小写的怪诞世界!如果你没有正确的答案,你将一无所获!我不知道为什么。也许它与.NET的System.Collections.Generic.Dictionary类和区分大小写的字符串键有关? 即

看起来$DP和$DP.Properties都是实现的对象,后者包含实例。能否运行$DP.Properties.GetType以查看该属性的运行时类型?您是否尝试过$DP.Properties['IsPXE']或$DP.Properties |?PropertyName-eq'IsPXE'?另外,在上一个代码片段中,为什么要使用EmbeddedProperties而不是Properties?看起来$DP和$DP.Properties都是实现的对象,后者包含实例。能否运行$DP.Properties.GetType以查看该属性的运行时类型?您是否尝试过$DP.Properties['IsPXE']或$DP.Properties |?PropertyName-eq'IsPXE'?另外,在您的上一个代码片段中,为什么要使用EmbeddedProperties而不是Properties?