Post by Jonathan HPost by Shane ThompsonPost 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