I am working in Powershell and the result of some queries return a collection member like this (note that this is shortened from the actual output):
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
I can access many of the items listed, such as "NetworkOSPath" and "RoleName" with code like this:
$myDP = $DP.NetworkOSPath
I am at a loss how to reference items listed in the Properties area such as:
IsPXE, IsPullDP and the values associated with them.
I can get a listing of them using the command: $dp.EmbeddedProperties | format-list *
This produces a listing of Keys and Values:
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 = "";
};
In an effort to just list a specific key, I've tried the following without success:
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}
Is there a way to reference the key and their associated values so that I can assign them to variables inside of my script?
You were so close with $dp.EmbeddedProperties
. Just keep dotting and you'll get there. Once you get the value you are looking for, you can add it to an object. Here's an example:
$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
BE CAREFUL - Once you dot-note passed EmbeddedProperties, you enter the eerie world of Case-Sensitivity! If you don't have it correct, you get NOTHING! I'm not sure why. perhaps it has something to do with the .NET's System.Collections.Generic.Dictionary class and Case-Sensitive String Keys? IE
$d.embeddedproperties.IsPXE.Value ##This works.
$d.embeddedproperties.IsPXe.Value ##This does not work.