DSCResources/ROACommon/Src/Get-ROALicense.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
function Get-ROALicense {
<#
    .SYNOPSIS
        Retrieves a RES ONE Automation site license from the database.
    .NOTES
        This cmdlet currently only support Microsoft SQL servers.
#>

    [CmdletBinding(DefaultParameterSetName = 'SQLAuth')]
    [OutputType([System.String])]
    param (
        # Database server hosting the RES ONE Automation database
        [Parameter(Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName)]
        [ValidateNotNullOrEmpty()]
        [System.String] $Server,

        # Name of the RES ONE Automation database/instance
        [Parameter(Mandatory, ValueFromPipelineByPropertyName)]
        [ValidateNotNullOrEmpty()]
        [System.String] $Database,

        # SQL authentication username and password
        [Parameter(Mandatory, ParameterSetName = 'SQLAuth')]
        [ValidateNotNull()]
        [System.Management.Automation.PSCredential]
        [System.Management.Automation.Credential()] $Credential,

        # Use the current Windows credentials for authentication
        [Parameter(ParameterSetName = 'WindowsAuth')]
        [System.Management.Automation.SwitchParameter]
        $UseWindowsAuthentication
    )
    process {

        try {

            $environmentGuid = (Get-ROAEnvironment @PSBoundParameters).ToString();
            $dirtySiteLicense = 'RES-{0}' -f $environmentGuid.TrimStart('{').TrimEnd('}');
            $cleanSiteLicense = $dirtySiteLicense.Insert(8, '-').Insert(33, '-').Insert(38, '-');
            return $cleanSiteLicense.ToUpper();

        }
        catch {

            throw;
        }

    } #end process
} #end function Get-ROALicense