Debian Codegraph @

ansible_collections/lowlydba/sqlserver/plugins/modules/sp_whoisactive.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 database = @{type = 'str'; required = $true }
18 local_file = @{type = 'str'; required = $false }
19 force = @{type = 'bool'; required = $false; default = $false }
20 }
21 }
22
23 $module = [Ansible.Basic.AnsibleModule]::Create($args, $spec, @(Get-LowlyDbaSqlServerAuthSpec))
24 $sqlInstance, $sqlCredential = Get-SqlCredential -Module $module
25 $database = $module.Params.database
26 $localFile = $module.Params.local_file
27 $force = $module.Params.force
28 $checkMode = $module.CheckMode
29 $module.Result.changed = $false
30
31 $whoIsActiveSplat = @{
32 SqlInstance = $SqlInstance
33 SqlCredential = $SqlCredential
34 Database = $Database
35 WhatIf = $checkMode
36 Force = $force
37 Confirm = $false
38 EnableException = $true
39 }
40 if ($null -ne $LocalFile) {
41 $whoIsActiveSplat.LocalFile = $LocalFile
42 }
43
44 try {
45 $output = Install-DbaWhoIsActive @whoIsActiveSplat
46 $module.Result.changed = $true
47
48 if ($null -ne $output) {
49 $resultData = ConvertTo-SerializableObject -InputObject $output
50 $module.Result.data = $resultData
51 }
52 $module.ExitJson()
53 }
54
55 catch {
56 $module.FailJson("Installing sp_WhoIsActive failed.", $_)
57 }