Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 8583

Converting PSCustomObject to String

$
0
0

Hello everyone and thank you for taking the time to read my post.   As my subject states, I'm looking to convert a PSCustomObject type to a String type.  At least, I think that is what I need to do.  Allow me to explain more about what I'm trying to accomplish.  I'm trying to learn more about how to use the ListView Class.  More information on the Class is available here:  http://msdn.microsoft.com/en-us/library/System.Windows.Forms.ListView.aspx

I have a form, that contains the ListView class.  I have three columns that I need to populate with data.  So far this is simple enough.  Here is the code that works to populate just one column:

$test = Get-ChildItem -Path 'HKLM:\SOFTWARE\test\test agent\myagent\2.0'`

| Get-ItemProperty | Where-Object {$_.'name' -and $_.hidden -eq '0'}`

| select -ExpandProperty 'Name'

When I run the above code, I get back the following results:

Agent 1

Agent 2

Agent 3

Agent 4

Agent 5

When I pipe $test to get-member it returns a system.string type.  It is my belief that because my results are returned as a system.string type, I can easily add the above code to my ListView class, and have the results nicely populated into column 1.

The problem occurs when I remove the select -expandproperty 'Name' portion of the code.  I do this because I need more than just Name returned.  I need Name, Install Location, and Version.  In order to return those values, my code now looks like this:

$test = Get-ChildItem -Path 'HKLM:\SOFTWARE\test\test agent\myagent\2.0'`

| Get-ItemProperty | Where-Object {$_.'name' -and $_.hidden -eq '0'}`

| select 'Name','Install Location','Version'

Now when I pipe $test to get-member, it returns as a PSCustomObject type.  I believe this is no good for ListView.  I just do not know how to add a PSCustomObject type to the ListView class.  Therefore, I'm assuming I need to convert or change the type to a string type.  My assumption could absolutely be wrong, and that is OK.  Please feel free to enlighten me :-)


Viewing all articles
Browse latest Browse all 8583

Trending Articles