2
votes

I try to run this PowerShell script to get counter.

[CmdletBinding()]
param (
    [Parameter(Mandatory = $true)]
    [String]
    $DatabaseName
)

$ErrorActionPreference = "Stop"
$VerbosePreference = "Continue"

cls

Write-Output "Collecting counters..."
Write-Output "Press Ctrl+C to exit."

$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") 

Get-Counter -Counter $counters -SampleInterval 1 -MaxSamples 3600 | 
    Export-Counter -FileFormat csv -Path "C:\sql-perfmon-log.csv" -Force

But I got error when ran the script.

Error on the screen.

I found out that error occur in "\SQLServer:Databases($DatabaseName)\Log Bytes Flushed/sec"

Can somebody prompt me How I can enter a specific instance probably with credentials?

1

1 Answers

0
votes

I see you're trying to run a powershell script from a command prompt.

Make sure you're doing this on the machine your SQL databases are hosted on.

You need to either open powershell administratively on your computer, or if you already have an administrative command prompt open, type "powershell" into it.

You can either paste all the code into your current host after specifying a string for $DatabaseName or just dot-source . the script and pass $DatabaseName as a parameter into the script.

If you're not sure what any of that means, take a look at https://technet.microsoft.com/en-us/library/dn425048.aspx for more information on getting started with using powershell.