Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Help with this output: {C05S02, VC05S02}

Reply
 
Old 06-14-2007   #1 (permalink)
Marc


 
 

Help with this output: {C05S02, VC05S02}

Got a little PS script that finds the active virtual sqlhost(s) on a
clustered host but the output is an ojbect and I'm trying to get to the text.
Can't seem to get to it.
PS F:\Proj\SQLSBuild> $candidate = "C05S02"
PS F:\Proj\SQLSBuild> $c = new-object -comobject MSCLuster.Cluster
PS F:\Proj\SQLSBuild> $c.open($candidate)
PS F:\Proj\SQLSBuild> $c.Resources | Where-Object -Filter {$_.Name -Match
"SQL Network Name"} `
>> | Where-Object -Filter {$_.OwnerNode.Name -eq $candidate} `
>> | Select {$_.OwnerNode.Name, $_.PrivateProperties.Item(1).Value }
>>


$_.OwnerNode.Name, $_.PrivateProperties.Item(1).Value
------------------------------------------------------
{C05S02, VC05S02}

How do I parse out the text CO5S02 and VC05S02 from the above object? Do the
curly braces indicate a hash?, object? in this context???

Thanks Much. -Marc

PS F:\Proj\SQLSBuild>

My System SpecsSystem Spec
Old 06-14-2007   #2 (permalink)
Kiron


 
 

Re: Help with this output: {C05S02, VC05S02}

Select-Object creates a NoteProperty of each object you specify in
the -Property parameter, and because you enclosed two properties of the
current pipeline object in curly braces the output is odd. It might be a
bug, because to create a calculated field you need to specify a '@{}'
(hashtable) to Select-Object's -Property parameter, but that has an '@'
before the opening curly brace, e.g.:

.... | select Name, @{Label='NameOfCalculatedField';Expression={<scriptblock
to execute>}}

Omit the curly braces in Select-Object and the current pipeline object '$_',
just specify the property names separated by a comma.

$candidate = "C05S02"
$c = new-object -comobject MSCLuster.Cluster
$c.open($candidate)
$c.Resources | Where-Object -Filter {$_.Name -Match "SQL Network Name"} `
| Where-Object -Filter {$_.OwnerNode.Name -eq $candidate} `
| Select OwnerNode.Name, PrivateProperties.Item(1).Value


--
Kiron

My System SpecsSystem Spec
Old 06-14-2007   #3 (permalink)
Marco Shaw


 
 

Re: Help with this output: {C05S02, VC05S02}

Marc wrote:
> Got a little PS script that finds the active virtual sqlhost(s) on a
> clustered host but the output is an ojbect and I'm trying to get to the text.
> Can't seem to get to it.
> PS F:\Proj\SQLSBuild> $candidate = "C05S02"
> PS F:\Proj\SQLSBuild> $c = new-object -comobject MSCLuster.Cluster
> PS F:\Proj\SQLSBuild> $c.open($candidate)
> PS F:\Proj\SQLSBuild> $c.Resources | Where-Object -Filter {$_.Name -Match
> "SQL Network Name"} `
>>> | Where-Object -Filter {$_.OwnerNode.Name -eq $candidate} `
>>> | Select {$_.OwnerNode.Name, $_.PrivateProperties.Item(1).Value }
>>>

>
> $_.OwnerNode.Name, $_.PrivateProperties.Item(1).Value
> ------------------------------------------------------
> {C05S02, VC05S02}
>
> How do I parse out the text CO5S02 and VC05S02 from the above object? Do the
> curly braces indicate a hash?, object? in this context???


I don't have a cluster with PowerShell to check this out.

There's a couple of ways to see how you determine what kind of object
this is (maybe others):

1. Run the entire command, but do as:
$output=$c.Resources | Where-Object -Filter...
Then:
$output.gettype()

or

2. Run the entire command, then pipe to get-member:
$c.Resources | Where-Object -Filter...|get-member

Then you can tell what kind of object you are dealing with.

What is your end goal though? I think your use of "{}" in the select is
causing the strange formatting.

Have you tried just doing this:
|Select $_.OwnerNode.Name, $_.PrivateProperties.Item(1).Value

Marco
My System SpecsSystem Spec
Old 06-14-2007   #4 (permalink)
Maximilian Hänel


 
 

Re: Help with this output: {C05S02, VC05S02}

Hi Kiron,

> Select-Object creates a NoteProperty of each object you specify in
> the -Property parameter, and because you enclosed two properties of the
> current pipeline object in curly braces the output is odd. It might be a
> bug, because to create a calculated field you need to specify a '@{}'


What happens here is that you pass a "ordinary" scriptblock as the
parameter and the scriptblock gets evaluated for each object in the
pipeline. If you look at the scripblock Marc passes to Select-Object
then you can see that it returns an array of two objects:

{$_.OwnerNode.Name, $_.PrivateProperties.Item(1).Value}

And this array is the content of the oddly named column. That's all the
magic. So if you want then

PS> gps | Select {$_.Name, $_.WS}

is nothing but a shortcut for

PS> gps | Select @{e={$_.Name, $_.WS}}

btw many cmdlets accept a scriptblock as a parameter e.g.:

PS> gps | group {$_.Name.ToUpper()[0]}

cu

Max
My System SpecsSystem Spec
Old 06-14-2007   #5 (permalink)
Kiron


 
 

Re: Help with this output: {C05S02, VC05S02}

Hi Max,
Thanks for clearing that up!
I thought it was a bug because there wasn't a clearly defined hasthtable,
but I now see that specifying a scriptblock in the -Property parameter is a
shortcut to create a 'label-less' hash.
Thanks again for the explanation.--
Kiron

My System SpecsSystem Spec
Old 06-14-2007   #6 (permalink)
Marc


 
 

Re: Help with this output: {C05S02, VC05S02}

Thanks Marco... yea Select vs. Select-Object doesn't seem to matter. Here's
the output from the pipe to Get-Member (has the type info too) Seems these
things are 'NoteProperties.' But if I assign them to a $var I get an object
not a string. Sorry, I'm very new to PS. I tried a bunch of stuff to get to
it, like $a.ToString() etc... Off to Google NoteProperty.

Thanks again. -Marc


PS F:\Proj\SQLSBuild> $candidate = "C05S02"
PS F:\Proj\SQLSBuild> $c = new-object -comobject MSCLuster.Cluster
PS F:\Proj\SQLSBuild> $c.open($candidate)
PS F:\Proj\SQLSBuild> $a = $c.Resources | Where-Object -Filter {$_.Name
-Match "SQL Network Name"} `
>> | Where-Object -Filter {$_.OwnerNode.Name -eq $candidate} `
>> | Select { $_.OwnerNode.Name, $_.PrivateProperties.Item(1).Value }
>>

PS F:\Proj\SQLSBuild> #$a.gettype()
PS F:\Proj\SQLSBuild> $a | get-member |ft


TypeName: System.Management.Automation.PSCustomObject

Name MemberType Definition
---- ---------- ----------
Equals Method
System.Boolean Equals(Object obj)
GetHashCode Method
System.Int32 GetHashCode()
GetType Method
System.Type GetType()
ToString Method
System.String ToString()
$_.OwnerNode.Name, $_.PrivateProperties.Item(1).Value NoteProperty
System.Management.Automation.PSObject $_.OwnerNo...


PS F:\Proj\SQLSBuild>

"Marco Shaw" wrote:

> Marc wrote:
> > Got a little PS script that finds the active virtual sqlhost(s) on a
> > clustered host but the output is an ojbect and I'm trying to get to the text.
> > Can't seem to get to it.
> > PS F:\Proj\SQLSBuild> $candidate = "C05S02"
> > PS F:\Proj\SQLSBuild> $c = new-object -comobject MSCLuster.Cluster
> > PS F:\Proj\SQLSBuild> $c.open($candidate)
> > PS F:\Proj\SQLSBuild> $c.Resources | Where-Object -Filter {$_.Name -Match
> > "SQL Network Name"} `
> >>> | Where-Object -Filter {$_.OwnerNode.Name -eq $candidate} `
> >>> | Select {$_.OwnerNode.Name, $_.PrivateProperties.Item(1).Value }
> >>>

> >
> > $_.OwnerNode.Name, $_.PrivateProperties.Item(1).Value
> > ------------------------------------------------------
> > {C05S02, VC05S02}
> >
> > How do I parse out the text CO5S02 and VC05S02 from the above object? Do the
> > curly braces indicate a hash?, object? in this context???

>
> I don't have a cluster with PowerShell to check this out.
>
> There's a couple of ways to see how you determine what kind of object
> this is (maybe others):
>
> 1. Run the entire command, but do as:
> $output=$c.Resources | Where-Object -Filter...
> Then:
> $output.gettype()
>
> or
>
> 2. Run the entire command, then pipe to get-member:
> $c.Resources | Where-Object -Filter...|get-member
>
> Then you can tell what kind of object you are dealing with.
>
> What is your end goal though? I think your use of "{}" in the select is
> causing the strange formatting.
>
> Have you tried just doing this:
> |Select $_.OwnerNode.Name, $_.PrivateProperties.Item(1).Value
>
> Marco
>

My System SpecsSystem Spec
Old 06-14-2007   #7 (permalink)
Marco Shaw


 
 

Re: Help with this output: {C05S02, VC05S02}

25# get-alias select

CommandType Name
Definition
----------- ----
----------
Alias select
Select-Object

"select" is just a shortcut to "select-object".

There may be other ways...

Try something like this:

....|Select $_.OwnerNode.Name, $_.PrivateProperties.Item(1).Value|
%{$name=$_.OwnerNode.Name,$value=$_.PrivateProperties.Item(1).Value}

(All on one-line. "%" is just a shortcut for "foreach-object".)

Then you should have what you're looking for in $name and $value.

This won't work if you have more than one line of output as $name and
$value would get overwritten with each run.

Not sure I'm explaining myself well...

Marco
My System SpecsSystem Spec
Old 06-14-2007   #8 (permalink)
Marc


 
 

Re: Help with this output: {C05S02, VC05S02}

Thanks Marco for the great help. That pretty much gets what I want. I
appreciate your help! -marc

"Marco Shaw" wrote:

> 25# get-alias select
>
> CommandType Name
> Definition
> ----------- ----
> ----------
> Alias select
> Select-Object
>
> "select" is just a shortcut to "select-object".
>
> There may be other ways...
>
> Try something like this:
>
> ....|Select $_.OwnerNode.Name, $_.PrivateProperties.Item(1).Value|
> %{$name=$_.OwnerNode.Name,$value=$_.PrivateProperties.Item(1).Value}
>
> (All on one-line. "%" is just a shortcut for "foreach-object".)
>
> Then you should have what you're looking for in $name and $value.
>
> This won't work if you have more than one line of output as $name and
> $value would get overwritten with each run.
>
> Not sure I'm explaining myself well...
>
> Marco
>

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Tab delimited output PowerShell
Enexpected output when using output-csv PowerShell
Tv output, PAL Vista music pictures video
No output from write-output PowerShell
Help output: what do they mean by this? PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46