Debian Codegraph @

ansible_collections/lowlydba/sqlserver/plugins/modules/memory.ps1

raw
1 #!powershell
2 # -*- coding: utf-8 -*-
3
4 # (c) 2022, John McCall (@lowlydba)
5 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
6
7 #AnsibleRequires -CSharpUtil Ansible.Basic
8 #AnsibleRequires -PowerShell ansible_collections.lowlydba.sqlserver.plugins.module_utils._SqlServerUtils
9 #Requires -Modules @{ ModuleName="dbatools"; ModuleVersion="2.0.0" }
10
11 $ErrorActionPreference = "Stop"
12
13 # Get Csharp utility module
14 $spec = @{
15 supports_check_mode = $true
16 options = @{
17 max = @{type = "int"; required = $false; default = 0 }
18 }
19 }
20
21 $module = [Ansible.Basic.AnsibleModule]::Create($args, $spec, @(Get-LowlyDbaSqlServerAuthSpec))
22 $sqlInstance, $sqlCredential = Get-SqlCredential -Module $module
23 $max = $module.Params.max
24 $checkMode = $module.CheckMode
25 $module.Result.changed = $false
26 $PSDefaultParameterValues = @{ "*:EnableException" = $true; "*:Confirm" = $false; "*:WhatIf" = $checkMode }
27
28 # Set max memory for SQL Instance
29 try {
30 # Set max memory
31 $setMemorySplat = @{
32 SqlInstance = $sqlInstance
33 SqlCredential = $sqlCredential
34 Max = $max
35 }
36 $output = Set-DbaMaxMemory @setMemorySplat
37
38 if ($output.PreviousMaxValue -ne $output.MaxValue -or $checkMode) {
39 $module.Result.changed = $true
40 }
41
42 if ($null -ne $output) {
43 $resultData = ConvertTo-SerializableObject -InputObject $output
44 $module.Result.data = $resultData
45 }
46 $module.ExitJson()
47 }
48 catch {
49 $module.FailJson("Error setting max memory.", $_)
50 }