Public/Get-AtwsConnectionObject.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#Requires -Version 4.0
<#
 
    .COPYRIGHT
    Copyright (c) ECIT Solutions AS. All rights reserved. Licensed under the MIT license.
    See https://github.com/ecitsolutions/Autotask/blob/master/LICENSE.md for license information.
 
#>


Function Get-AtwsConnectionObject {
    <#
        .SYNOPSIS
            This function returns a SOAPClient Object with the active connection to Autotask Web Api from the current namespace.
        .DESCRIPTION
            This function returns a SOAPClient Object with the active connection to Autotask Web API from the current namespace.
            Advanced users may use this object for direct access to API methods or hardcoded queries. It may also be useful for
            debugging.
        .INPUTS
            Nothing.
        .OUTPUTS
            [Autotask.SOAPClient]
        .EXAMPLE
            $Atws = Get-AtwsConnectionObject
            Gets a SOAPClient Object with the active connection to Autotask Web Api from the current namespace.
        .NOTES
            NAME: Get-AtwsConnectionObject
       
  #>

    
    [cmdletbinding(SupportsShouldProcess = $true, ConfirmImpact = 'High')]
    Param()
  
    begin {
        # Enable modern -Debug behavior before the first Write-Debug
        if ($PSCmdlet.MyInvocation.BoundParameters['Debug'].IsPresent) { $DebugPreference = 'Continue' }
    
        Write-Verbose ('{0}: Begin of function' -F $MyInvocation.MyCommand.Name)
    
        if (-not($Script:Atws.integrationsValue)) {
            Throw [ApplicationException] 'Not connected to Autotask WebAPI. Re-import module with valid credentials.'
        }    
    
    }

    process {
        Write-Verbose ('{0}: End of function' -F $MyInvocation.MyCommand.Name)
        
        $caption = $MyInvocation.MyCommand.Name
        $verboseDescription = '{0}: About to return the Web Proxy Object for the current connection Autotask Web API. This will expose your credentials in clear text in your terminals variable scope.' -F $caption
        $verboseWarning = '{0}: About to return the Web Proxy Object for the current connection Autotask Web API. This will expose your credentials in clear text in your terminals variable scope. Do you want to continue?' -F $caption
        
        if ($PSCmdlet.ShouldProcess($verboseDescription, $verboseWarning, $caption)) { 
            Return $Script:Atws
        }
    }

    end {
        Write-Debug ('{0}: End of function' -F $MyInvocation.MyCommand.Name)
    }
}