Discussion:
Shorten InstanceName on Get-Counter Table
(too old to reply)
Jonathan H
2015-04-06 21:14:19 UTC
Permalink
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
2015-04-07 03:53:18 UTC
Permalink
Post by Jonathan H
$Holes = get-counter "\IPTV DServer Services(*)\Holes"
$Holes.CounterSamples | Where-Object {$_.CookedValue -gt 0} | Format-Table -Property InstanceName, CookedValue -AutoSize
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.
<# 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
2015-04-07 16:18:21 UTC
Permalink
Post by Shane Thompson
Post by Jonathan H
$Holes = get-counter "\IPTV DServer Services(*)\Holes"
$Holes.CounterSamples | Where-Object {$_.CookedValue -gt 0} | Format-Table -Property InstanceName, CookedValue -AutoSize
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.
<# 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
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. #>
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
2015-04-07 17:25:36 UTC
Permalink
Post by Jonathan H
Post by Shane Thompson
Post by Jonathan H
$Holes = get-counter "\IPTV DServer Services(*)\Holes"
$Holes.CounterSamples | Where-Object {$_.CookedValue -gt 0} | Format-Table -Property InstanceName, CookedValue -AutoSize
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.
<# 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
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. #>
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.
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
2015-04-07 17:36:27 UTC
Permalink
Post by Jonathan H
Post by Jonathan H
Post by Shane Thompson
Post by Jonathan H
$Holes = get-counter "\IPTV DServer Services(*)\Holes"
$Holes.CounterSamples | Where-Object {$_.CookedValue -gt 0} | Format-Table -Property InstanceName, CookedValue -AutoSize
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.
<# 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
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. #>
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.
Actually I might of broken it. I opened a new instance of it and ran it, but got an error message this time.
$New_Variable = $Holes.CounterSamples | Where-Object {$_.CookedValue -gt 0} | Select InstanceName, CookedValue
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
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
I'm dumb. I forgot the first cmd. $Holes = get-counter "\IPTV DServer Services(*)\Holes"
Ok, I'm done. lol
issdr
2015-04-07 20:10:14 UTC
Permalink
Post by Jonathan H
$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
2015-04-08 03:38:45 UTC
Permalink
sorry as I did not have notifications turned on just now read this, I'm interested in your split syntax, link to referencing?
issdr
2015-04-08 17:57:09 UTC
Permalink
Post by Shane Thompson
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
Post by Shane Thompson
Expression={($_.InstanceName -split '|', 2)[1]}}, `
becomes

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

sorry about that, hth
--
np: no song
Loading...