SQL “Log Bytes Flushed/sec” counter from powershell Error

你离开我真会死。 提交于 2019-12-12 03:36:18

问题


I am trying to calculate the type of AZURE SQL I need using this: http://dtucalculator.azurewebsites.net/ => http://dtucalculator.azurewebsites.net/Downloads/sql-perfmon.zip

This is a PowerShell script that gets data from some counters from SQL but it errors out when accessing the "Log Bytes Flushed/sec" counter that it is pressent in SQL when I run

select *  FROM sys.dm_os_performance_counters where counter_name like 'Log Bytes Flushed/sec%'

the error I get from PowerShell is:

Get-Counter : The specified object was not found on the computer. At C:\users\ringhel\desktop\sql-perfmon.ps1:47 char:1 + Get-Counter -Counter $counters -SampleInterval 1 -MaxSamples 3600 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidResult: (:) [Get-Counter], Exception + FullyQualifiedErrorId : CounterApiError,Microsoft.PowerShell.Commands.GetCounterCommand

The error comes from this variable:

$counters = @("\Processor(_Total)\% Processor Time", "\LogicalDisk(C:)\Disk Reads/sec", "\LogicalDisk(C:)\Disk Writes/sec",

"\LogicalDisk(C:)\Disk Read Bytes/sec", "\LogicalDisk(C:)\Disk Write Bytes/sec", "\SQLSERVER:Databases($DatabaseName)\Log Bytes Flushed/sec")

After searching the web, instead of SQLSERVER I tried MSSQLSERVER (this is the instance name of the SQL server), MSSQL'$MSSQLSERVER and MSSQL$MSSQLSERVER but the same error.

Please help.


回答1:


found the problem. I had to set the execution policy for the LocalMachine to RemoteSigned. It was Undefined.

Set-ExecutionPolicy RemoteSigned -Scope LocalMachine




回答2:


My issue was slightly different. For a named instance I had to define the SQL Server counter like this:

\MSSQL`$SQL2016:Databases(_Total)\Log Bytes Flushed/sec

My instance was named "SQL2016". The back tick escapes the $ in the instance name.



来源:https://stackoverflow.com/questions/35677804/sql-log-bytes-flushed-sec-counter-from-powershell-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!