Get-Counter not accepting array created from SQL
0
votes
0
answers
247
views
When I try and generate an array from a SQL output, although it's the same data type and content, perfmon doesn't accept these values, whereas it does for a manually created a list. So the first call for Get-Counter returns an error message as seen below, where as the second call with a manually created list works correctly. How do I resolve this?
Get-Counter : Internal performance counter API call failed. Error: c0000bc4.
At line:26 char:9
$SQLQueryGetCounters = "
DECLARE @PerfmonCounterList VARCHAR(MAX)
SELECT
TOP 2
PerfmonCounter
FROM
Perfmon.PerfmonCounterList"
$SQLQueryGetCounters = "
DECLARE @PerfmonCounterList VARCHAR(MAX)
SELECT top 2
'
"' +PerfmonCounter + '
"' ItemValue
FROM
Perfmon.PerfmonCounterList "
$Counters = @(Invoke-sqlcmd -ServerInstance Localhost -Database "DatabaseMonitoring" -Query $SQLQueryGetCounters )| select-object -expand ItemValue
$List = [System.Collections.ArrayList]@() # New-Object System.Collections.Generic.List[System.Object] # [System.Collections.ArrayList]@()
foreach ($Item in $Counters)
{
$List.Add($Item)
}
$List = $List.ToArray()
Get-Counter -Counter $List
$List = "\DATABASE(*)\DATABASE CACHE % HIT","\DATABASE(*)\DATABASE CACHE SIZE (MB)"
Get-Counter -Counter $List
Asked by Krishn
(13 rep)
Jan 17, 2020, 11:04 AM