Functions/CatalogItems/Rest/New-RsRestCredentialsInServerObject.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
# Copyright (c) 2017 Microsoft Corporation. All Rights Reserved.
# Licensed under the MIT License (MIT)

function New-RsRestCredentialsInServerObject
{
    <#
        .SYNOPSIS
            This script creates a new CredentialsInServer object which can be used when updating shared/embedded data sources.

        .DESCRIPTION
            This script creates a new CredentialsInServer object which can be used when updating shared/embedded data sources.

        .PARAMETER Username
            Specify the username to use when Report Server is connecting to database.

        .PARAMETER Password
            Specify the password to use when Report Server is connecting to database.

        .PARAMETER WindowsCredentials
            Specify whether Report Server should treat specified credentials as SQL credentials or Windows credentials.

        .PARAMETER ImpersonateUser
            Specify whether Report Server should try impersonating as current user when fetching data.

        .EXAMPLE
            New-RsRestCredentialsInServerObject -Credential (Get-Credential)

            Description
            -----------
            Creates a CredentialsInServer object with specified username and password.

        .EXAMPLE
            New-RsRestCredentialsInServerObject -Credential (Get-Credential) -WindowsCredentials

            Description
            -----------
            Creates a CredentialsInServer object with UseAsWindowsCredentials set to true and specified username and password.

        .EXAMPLE
            New-RsRestCredentialsInServerObject -Credential (Get-Credential) -ImpersonateUser

            Description
            -----------
            Creates a CredentialsInServer object with ImpersonateAuthenticatedUser set to true and specified username and password.
    #>

    [CmdletBinding()]
    param(
        [Parameter(Mandatory = $True)]
        [System.Management.Automation.PSCredential]
        $Credential,

        [Alias('UseAsWindowsCredentials')]
        [switch]
        $WindowsCredentials,

        [Alias('ImpersonateAuthenticatedUser')]
        [switch]
        $ImpersonateUser
    )
    Process
    {
        return @{
            "UserName" = $Credential.Username;
            "Password" = $Credential.GetNetworkCredential().Password;
            "UseAsWindowsCredentials" = $WindowsCredentials -eq $true;
            "ImpersonateAuthenticatedUser" = $ImpersonateUser -eq $true;
        }
    }
}