Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Shorten InstanceName on Get-Counter Table

25 views
Skip to first unread message

Jonathan H

unread,
Apr 6, 2015, 5:14:21 PM4/6/15
to
code:
$Holes = get-counter "\IPTV DServer Services(*)\Holes"
$Holes.CounterSamples | Where-Object {$_.CookedValue -gt 0} | Format-Table -Property InstanceName, CookedValue -AutoSize

output:
InstanceName CookedValue
------------ -----------
mssnks2074hd|6675dd55-3997-47d6-bbf2-078e764d26b0 1
blahblah|324234 1
Blacblabh|56444 2
ect.
ect.
ect.
the table is pretty long.

I would like to return everything to the right of "|" excluding the "|".
tips or suggestions much appreciated.
Thank you guys.

Shane Thompson

unread,
Apr 6, 2015, 11:53:19 PM4/6/15
to
<# My Response - Shane Thompson #>

I'm going to remove the Format-Table portion of the last line you provided as Format-Table is great for viewing results, but not scripting, and then set it to a new variable ($New_Variable).

$New_Variable = $Holes.CounterSamples | Where-Object {$_.CookedValue -gt 0} | Select InstanceName, CookedValue

$Array = @()
ForEach ($Line in $New_Variable) {

$New_InstanceName = $Line.InstanceName.Substring( ($Line.InstanceName.indexof("|") + 1),$Line.InstanceName.Length - $Line.InstanceName.LastIndexOf("|") - 1)

$Object = New-Object -TypeName psobject
$Object | Add-Memeber -MemberType NoteProperty -Name "InstanceName" -Value $New_InstanceName
$object | Add-Member -MemberType NoteProperty - Name "CookedValue" -Value $Line.CookedValue

$Array += $Object

}

$Array <# The Array variable should have all the information, just double check everything as I am unable to access a PowerShell session at the time being =] using my Chromebook lol Reply with any errors, I'll see what I can do. #>

Jonathan H

unread,
Apr 7, 2015, 12:18:21 PM4/7/15
to
All works great(other than a couple syntax errors) thank you Shane,
My mistake was asking to return everything right of the "|" when I meant left of the "|". I'll look up "indexof" and see if I can't figure it out on my own, but if you could show me that would be great too.

Jonathan H

unread,
Apr 7, 2015, 1:25:37 PM4/7/15
to
Actually I might of broken it. I opened a new instance of it and ran it, but got an error message this time.
code:
$New_Variable = $Holes.CounterSamples | Where-Object {$_.CookedValue -gt 0} | Select InstanceName, CookedValue

$Array = @()
ForEach ($Line in $New_Variable) {

$New_InstanceName = $Line.InstanceName.Substring( 0, $Line.InstanceName.indexof("|") + 1)

$Object = New-Object -TypeName psobject
$Object | Add-Member -MemberType NoteProperty -Name "InstanceName" -Value $New_InstanceName
$object | Add-Member -MemberType NoteProperty -Name "CookedValue" -Value $Line.CookedValue

$Array += $Object

}

$Array

error:
You cannot call a method on a null-valued expression.
At C:\Users\Jonathan.Hauxwell\Documents\Dserv GetCounter Holes.ps1:6 char:85
+ $New_InstanceName = $Line.InstanceName.Substring( 0, $Line.InstanceName.indexof <<<< ("|") + 1)
+ CategoryInfo : InvalidOperation: (indexof:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull

Jonathan H

unread,
Apr 7, 2015, 1:36:29 PM4/7/15
to
I'm dumb. I forgot the first cmd. $Holes = get-counter "\IPTV DServer Services(*)\Holes"
Ok, I'm done. lol

issdr

unread,
Apr 7, 2015, 4:10:17 PM4/7/15
to
Jonathan H wrote:

> $Holes = get-counter "\IPTV DServer Services(*)\Holes"

$Holes.CounterSamples | `
where {$_.CookedValue -gt 0} | `
ft @{Label="InstanceName"; `
Expression={($_.InstanceName -split '|', 2)[1]}}, `
CookedValue -AutoSize


cannot test it here, but it should work

--
np: no song

Shane Thompson

unread,
Apr 7, 2015, 11:38:46 PM4/7/15
to
sorry as I did not have notifications turned on just now read this, I'm interested in your split syntax, link to referencing?

issdr

unread,
Apr 8, 2015, 1:57:11 PM4/8/15
to
Shane Thompson wrote:

> sorry as I did not have notifications turned on just now read this,
> I'm interested in your split syntax, link to referencing?

help about_split (which i should have read before posting)

the syntax i used has a regex to define delimiter(s), thus

> Expression={($_.InstanceName -split '|', 2)[1]}}, `

becomes

Expression={($_.InstanceName -split '\|', 2)[1]}}, `

sorry about that, hth

--
np: no song
0 new messages