commands

^

Get-DbaMemoryUsage

Author Klaas Vandenberghe (@PowerDBAKlaas)
Availability Windows, Linux, macOS

 

Want to see the source code for this command? Check out Get-DbaMemoryUsage on GitHub.
Want to see the Bill Of Health for this command? Check out Get-DbaMemoryUsage.

Synopsis

Get amount of memory in use by all SQL Server components and instances

Description

Retrieves the amount of memory per performance counter. Default output includes columns Server, counter instance, counter, number of pages, memory in KB, memory in MB SSAS and SSIS are included.

SSRS does not have memory counters, only memory shrinks and memory pressure state.

This function requires local admin role on the targeted computers.

Syntax

Get-DbaMemoryUsage
    [[-ComputerName] <DbaInstanceParameter[]>]
    [[-Credential] <PSCredential>]
    [[-MemoryCounterRegex] <String>]
    [[-PlanCounterRegex] <String>]
    [[-BufferCounterRegex] <String>]
    [[-SSASCounterRegex] <String>]
    [[-SSISCounterRegex] <String>]
    [-EnableException]
    [<CommonParameters>]

 

Examples

 

Example: 1
PS C:\> Get-DbaMemoryUsage -ComputerName sql2017

Returns a custom object displaying Server, counter instance, counter, number of pages, memory

Example: 2
PS C:\> Get-DbaMemoryUsage -ComputerName sql2017\sqlexpress -SqlCredential sqladmin | Where-Object { $_.Memory.Megabyte -gt 100 }

Logs into the sql2017\sqlexpress as sqladmin using SQL Authentication then returns results only where memory exceeds 100 MB

Example: 3
PS C:\> $servers | Get-DbaMemoryUsage | Out-Gridview

Gets results from an array of $servers then diplays them in a gridview.

Optional Parameters

-ComputerName

The Windows Server that you are connecting to. Note that this will return all instances, but Out-GridView makes it easy to filter to specific instances.

Alias Host,cn,Server
Required False
Pipeline true (ByValue)
Default Value $env:COMPUTERNAME
-Credential

Login to the target instance using alternative credentials. Accepts PowerShell credentials (Get-Credential). Windows Authentication, SQL Server Authentication, Active Directory - Password, and Active Directory - Integrated are all supported. For MFA support, please use Connect-DbaInstance.

Alias
Required False
Pipeline false
Default Value
-MemoryCounterRegex

Regular expression that is applied to the paths of the counters returned for the counter list set 'sql:Memory Manager*' to display relevant Memory Manager counters. Default: '(Total Server Memory |Target Server Memory |Connection Memory |Lock Memory |SQL Cache Memory |Optimizer Memory |Granted Workspace Memory |Cursor memory usage|Maximum Workspace)' The default works for English language systems and has to be adapted for other languages.

Alias
Required False
Pipeline false
Default Value (Total Server Memory Target Server Memory Connection Memory Lock Memory SQL Cache Memory Optimizer Memory Granted Workspace Memory Cursor memory usage Maximum Workspace)
-PlanCounterRegex

Regular expression that is applied to the paths of the counters returned for the counter list set 'sql:Plan Cache*' to display relevant Plan Cache counters. Default: '(cache pages|procedure plan|ad hoc sql plan|prepared SQL Plan)' The default works for English language systems and has to be adapted for other languages.

Alias
Required False
Pipeline false
Default Value (cache pages procedure plan ad hoc sql plan prepared SQL Plan)
-BufferCounterRegex

Regular expression that is applied to the paths of the counters returned for the counter list set 'Buffer Manager' to display relevant Buffer Manager counters. Default: '(Free pages|Reserved pages|Stolen pages|Total pages|Database pages|target pages|extension .* pages)' The default works for English language systems and has to be adapted for other languages.

Alias
Required False
Pipeline false
Default Value (Free pages Reserved pages Stolen pages Total pages Database pages target pages extension .* pages)
-SSASCounterRegex

Regular expression that is applied to the paths of the counters returned for the counter list set 'MSAS*:Memory' to display relevant SSAS counters. Default: '(\memory )' The default works for English language systems and has to be adapted for other languages.

Alias
Required False
Pipeline false
Default Value (\memory )
-SSISCounterRegex

Regular expression that is applied to the paths of the counters returned for the counter list set 'SSIS' to display relevant SSIS counters. Default: '(memory)' The default works for English language systems and has to be adapted for other languages.

Alias
Required False
Pipeline false
Default Value (memory)
-EnableException

By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message. This avoids overwhelming you with "sea of red" exceptions, but is inconvenient because it basically disables advanced scripting. Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own try/catch.

Alias
Required False
Pipeline false
Default Value False