Public/Get-AtwsWsdlVersion.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
61
62
63
64
65
66
67
68
69
#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-AtwsWsdlVersion {
    <#
        .SYNOPSIS
            This function gets the current API version from the Autotask servers.
        .DESCRIPTION
            The function calls GetWsdlVersion() and returns the result.
        .INPUTS
            Nothing.
        .OUTPUTS
            ATWSResponse
        .EXAMPLE
            Get-AtwsWsdlVersion
            gets the current API version from the Autotask servers.
         
        .NOTES
            NAME: Get-AtwsWsdlVersion
       
  #>

    
  [cmdletbinding()]
  Param
  (
  )
  
    begin {    
        # Enable modern -Debug behavior
        if ($PSCmdlet.MyInvocation.BoundParameters['Debug'].IsPresent) { $DebugPreference = 'Continue' }
   
        Write-Debug ('{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 {
        try { 
            Write-Verbose ('{0}: Calling GetWsdlVersion()' -F $MyInvocation.MyCommand.Name)

            $result = $Script:Atws.GetWsdlVersion($Script:Atws.IntegrationsValue)
        }
        catch {
            throw (New-Object System.Net.WebException ('{0}: FAILED on GetWsdlVersion($Script:Atws.IntegrationsValue). No data returned.' -F $MyInvocation.MyCommand.Name))       
            Return
        }

        # Handle any errors
        if ($result.Errors.Count -gt 0) {
            foreach ($AtwsError in $result.Errors) {
                Write-Error $AtwsError.Message
            }
            Return
        }
    }
    

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