1

I have this object in Powershell which I obtained from a query against the SSRS Web Service:

$ds|gm


TypeName: Microsoft.PowerShell.Commands.NewWebserviceProxy.AutogeneratedTypes.WebServiceProxy3tServer_ReportService2010_asmx.DataSource

Name        MemberType Definition
----        ---------- ----------

Equals      Method     bool Equals(System.Object obj)                    
GetHashCode Method     int GetHashCode()
GetType     Method     type GetType()
ToString    Method     string ToString()
Item        Property   Microsoft.PowerShell.Commands.NewWebserviceProxy.AutogeneratedTypes.WebServiceProxy3tServer_ReportService2010_asmx.DataSourceDe...
Name        Property   string Name {get;set;} 

If I list the $ds object:

$ds|fl

Name : AHPUsersData
Item : Microsoft.PowerShell.Commands.NewWebserviceProxy.AutogeneratedTypes.WebServiceProxy3tServer_ReportService2010_asmx.DataSourceReference

What I need is the value of "Item" which actually appears to be the type of an object stored in "Item". I've try assigning $ds.Item to a new object but it just turns into a Powershell custom object and all that info goes away. I've tried various combinations of GetType with no success. Ultimately what I need is the last part of:

Microsoft.PowerShell.Commands.NewWebserviceProxy.AutogeneratedTypes.WebServiceProxy3tServer_ReportService2010_asmx.DataSourceReference

Which is the "DataSourceReference" string. This part can have two values, "DataSourceReference" or "DataSourceDefinition" and I need to test that to determine the code to execute next.

Relative newbie to Powershell and this one is a bit obtuse for me. Any help is greatly appreciated.

3
  • what does $ds | select -expand Item return? Commented Jul 18, 2016 at 12:07
  • Perfect!!! Want to post as an Answer so I can flag it? Commented Jul 18, 2016 at 15:50
  • Sure. Glad it worked :) Commented Jul 18, 2016 at 16:41

2 Answers 2

1

Just expand the Item with Select-Object:

$ds | select -expand Item
Sign up to request clarification or add additional context in comments.

Comments

0

I don't know exactly what you need, but you could also create your own custom PSCustomObject like this:

[PSCustomObject]@{
    Name                = $ds.Name
    DataSourceReference = $ds.Item.DataSourceReference
    SomethingElse       = $ds.Item | Select-Object -ExpandProperty DataSourceReference
}

At first you select the PropertyName and then the PropertyValue, which can be anything you like. Hopefully this helps you out.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.