![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | how to get text string from description? Just started to play with powershll and is using CTP2. $a = get-help write-error $b = $a.description If I typed $b, I get Quote: > The Write-Error cmdlet writes an object to the error pipeline. You can use this cmdlet to generate error messages along with othe Cool. I then try $a.name + $b, I get Quote: > Write-Error Quote: > Write-Error The Write-Error cmdlet writes an object to the error pipeline. You can use this cmdlet to generate error messages along with othe What am I missing. Thank you. |
My System Specs![]() |
| | #2 (permalink) |
| | Re: how to get text string from description? Quote: > Why? I am expecting this: > Quote: >> Write-Error The Write-Error cmdlet writes an object to the error pipeline. You can use this cmdlet to generate error messages along with othe > > What am I missing. Thank you. How about: $a|foreach-object{$_.name,$_.description} The problem is that the addition operator can't be used for the particular objects you're dealing with. $a.gettype() doesn't return a string object. I've not played with it enough, but there's a method to get a string out of this, but even it doesn't work properly at first glance: $a.name.tostring() + $b.tostring() Maybe casting $a and $b to a string when creating them will help: [string]$a=get-help write-error etc. Marco -- Microsoft MVP - Windows PowerShell http://www.microsoft.com/mvp PowerGadgets MVP http://www.powergadgets.com/mvp Blog: http://marcoshaw.blogspot.com |
My System Specs![]() |
| | #3 (permalink) |
| | Re: how to get text string from description? Thanks for your reply Marco. You do give me more ideas to try out. I found out that $a.description is of type PSObject[], not string. So, if I use "$a.name + $a.description[0].text", it gives me my expected result. Quote: > You absolutely need that exact syntax? don't understand. If I say "$a | get-member -name description", I get description NoteProperty System.Management.Automation.PSObject[] description=System.Management.Automation.PSObject[] in one of the output lines. It says it is type PSObject[] (powershell object array?). Ok. Then I try "$a.description.GetType()", I get True True PSObject[] System.Array which seems to comfirm that the "description" property is PSObject[] type. Then I say "$b = $a.description", then "$b.GetType()", it says it is String type? Why? And at this point, $b is a empty string. Why? Why do I have to say [PSObject[]]$b = $a.description to make $b of type PSObject[]? Thank you. |
My System Specs![]() |
| | #4 (permalink) |
| | Re: how to get text string from description? "DarrickIvy" <DarrickIvy@xxxxxx> wrote in message news:30B495F4-64EF-429D-9859-D382CF410615@xxxxxx Quote: > Thanks for your reply Marco. You do give me more ideas to try out. I > found > out that $a.description is of type PSObject[], not string. So, if I use > "$a.name + $a.description[0].text", it gives me my expected result. > Quote: >> You absolutely need that exact syntax? > No. I am simply playing around to get used to powershell. This is what I > don't understand. If I say "$a | get-member -name description", I get > > description NoteProperty System.Management.Automation.PSObject[] > description=System.Management.Automation.PSObject[] > > in one of the output lines. It says it is type PSObject[] (powershell > object array?). > > Ok. Then I try "$a.description.GetType()", I get > > True True PSObject[] System.Array > > which seems to comfirm that the "description" property is PSObject[] type. > > Then I say "$b = $a.description", then "$b.GetType()", it says it is > String > type? Why? 38> $b.GetType() IsPublic IsSerial Name BaseType -------- -------- ---- -------- True True PSObject[] System.Array Is it possible that you have turned $b into a variable of type string? For instance, if you execute a statement like this: [string]$b = ... Then $b will only contain a string and PowerShell will try real hard to convert everything to a string to fit into that variable. Try you experiment with a different/new variable and see if you get the same results: -- Keith |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Concatenate text string and text in variable with no space between | PowerShell | |||
| Concatenate text string and text in variable with no space between | VB Script | |||
| Creating a Text string | PowerShell | |||
| Re: Err.Description does not contain the full text of the error me | VB Script | |||
| How to search and replace text in a string | PowerShell | |||