Public/Initialize-bConnect.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
Function Initialize-bConnect() {
    <#
        .Synopsis
            Initialize the connection to bConnect.
        .Parameter Server
            Hostname/FQDN/IP of the baramundi Management Server.
        .Parameter Port
            Port of bConnect (default: 443).
        .Parameter Credentials
            PSCredential-object with permissions in the bMS.
        .Parameter AcceptSelfSignedCertificate
            Switch to ignore untrusted certificates.
    #>


    Param(
        [Parameter(Mandatory=$true)][string]$Server,
        [string]$Port = "443",
        [Parameter(Mandatory=$true)][System.Management.Automation.PSCredential]$Credentials,
        [switch]$AcceptSelfSignedCertifcate
    )

    If($AcceptSelfSignedCertifcate) {
        [System.Net.ServicePointManager]::CertificatePolicy = New-Object ignoreCertificatePolicy
    }

    $_uri = "https://$($Server):$($Port)/bConnect"

    $script:_connectUri = $_uri
    $script:_connectCredentials = $Credentials
    $script:_connectInitialized = $true
}