How to use property "-filter" in Get-SCSMObjectProjection

Nov 10, 2010 at 3:35 PM

Hi

I want to obtain a certain instance by using "-Filter"  in "Get-SCSMObjectProjection" cmdlet.
For example:
    $CRP = Get-SCSMTypeProjection -Name System.WorkItem.ChangeRequestProjection$
    Get-SCSMObjectProjection -ProjectionName $CRP.Name -Filter ?????? 

regards

Vladimir

 

Developer
Nov 10, 2010 at 11:27 PM

The filter command only allows you to filter against the projection seed object, so in this case, you could do the following:

$CRP = get-scsmtypeprojection -name System.WorkItem.ChangeRequestProjection
Get-scsmobjectprojection -ProjectionName $CRP.Name -filter "DisplayName -like '%lorem%'"

(or another property on System.WorkItem.ChangeRequest)

 

jim

Apr 28, 2011 at 3:38 AM

Hi Jim,

Is it possible to run something like this?

Get-SCSMObjectProjection $IncidentProjection -Filter "AssignedTo -eq $null"

I'm getting this error:

Get-SCSMObjectProjection : This constructor accepts criteria in xml format only. Use a different constructor for string criteria usage.

 

If not, is it possible to use a criteria type? (like "Microsoft.EnterpriseManagement.Common.EnterpriseManagementObjectCriteria")

I don't know what would be the criteria type in such case.

 

Thanks!

German

Apr 28, 2011 at 1:28 PM
$ComputerName = "My_SCSM_ManagementServer "
$CPT = "System.WorkItem.Incident.ProjectionType"
$ID=$ID_IR.ID #It's should be the ID of Incident
$IncidentProjection = Get-scsmobjectprojection -ProjectionName $CPT -filter "ID -eq  $ID" -ComputerName $ComputerName

For today, I don't remember exactly but it's worked

Developer
Apr 29, 2011 at 12:45 AM

the filter applies only to the seed of the projection. This means that you can only create filters which query properties against the seed object (in this case an incident) Filter in Get-SCSMObjectProjection doesn't yet support traversing the relationships of a projection. You can create an ProjectionCriteria if you need more than this.

May 3, 2011 at 2:51 PM

Do you know what's the full name of the ProjectionCriteria?

I'm using this for classes: "Microsoft.EnterpriseManagement.Common.EnterpriseManagementObjectCriteria"

Developer
May 3, 2011 at 8:09 PM

the class you should use is:

Microsoft.EnterpriseManagement.Common.ObjectProjectionCriteria

Here's an example:

$projection = get-scsmtypeprojection System.WorkItem.Incident.View.ProjectionType
$CTYPE = "Microsoft.EnterpriseManagement.Common.ObjectProjectionCriteria"
$C = @'
<Criteria xmlns="http://Microsoft.EnterpriseManagement.Core.Criteria/">
<Reference Id="System.WorkItem.Incident.Library" PublicKeyToken="9396306c2be7fcc4" Version="7.5.1168.0" Alias="WorkItem" />
<Expression>
<SimpleExpression>
<ValueExpressionLeft>
<Property>$Context/Property[Type='WorkItem!System.WorkItem.Incident']/Id$</Property>
</ValueExpressionLeft>
<Operator>Equal</Operator>
<ValueExpressionRight>
<Value>customir10263</Value>
</ValueExpressionRight>
</SimpleExpression>
</Expression>
</Criteria>
'@
$criteria = new-object $CTYPE $C,$projection.__Base,$projection.managementgroup
get-scsmobjectprojection -criteria $criteria

note that this specific example probably won't work for you, but if you change "customir10263" in the criteria to something else, then that should work.

May 3, 2011 at 9:22 PM

Thanks, Jim! That's exactly what I was looking for! :)