issue using -filter switch on get-scsmobject

Feb 15, 2013 at 2:14 PM
Having trouble with this bit of code... the -filter is not working as I would expect.

$MAID is set from the authoring tool

Everything works up to the last line.

Gets the MAobj

$MAobj = Get-SCSMObject -Class $MAClass -Filter "ID -eq $MAID"

Filters out the All Activites Q, (no other Qs exist)

$ParentCR = Get-SCSMRelationshipObject -ByTarget $MAobj | ? {$_.sourceobject.tostring() -ne "All Activities Queue"}

Gets the CR displayname from the source object in the relationship

[string]$CRdisplayname = $ParentCR.SourceObject.DisplayName

Attempts to pull the CR based on the above values.

$CRobj = Get-SCSMObject -Class $CRClass -Filter "Displayname -eq $CRdisplayname"

Nothing is returned, no error... no results.

But if I do this,

Get-SCSMObject -Class $CRClass | ?{$_.displayname -eq "CR7554: Are we able to hide these in the Navigation Pane?"}

I get the CR as expected. I can even do this,

Get-SCSMObject -Class $CRClass | ?{$_.displayname -eq "$CRdisplayname?"}

And it works as expected.
Feb 15, 2013 at 4:14 PM
Additionally, I have removed the extra Queue, and simplified the code, and still have the same issue...
$MAobj = Get-SCSMObject -Class $MAClass -Filter "ID -eq $MAID"
[string]$CRDisplayname = (Get-SCSMRelationshipObject -ByTarget $MAobj).sourceobject.displayname
$CRobj = Get-SCSMObject -Class $CRClass -Filter "Displayname -eq $CRDisplayname"
Feb 15, 2013 at 4:45 PM
BAH!!! I fixed it...
$MAobj = Get-SCSMObject -Class $MAClass -Filter "ID -eq $MAID"
[string]$CRID = (Get-SCSMRelationshipObject -ByTarget $MAobj).sourceobject.name
$CRobj = Get-SCSMObject -Class $CRClass -Filter "Id -eq $CRID"