Functions/Utilities/New-RsCatalogItemRoleObject.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
# Copyright (c) 2016 Microsoft Corporation. All Rights Reserved.
# Licensed under the MIT License (MIT)

function New-RscatalogItemRoleObject
{
    <#
        .SYNOPSIS
            This script creates a new Catalog Item Role Object.
        
        .DESCRIPTION
            This script creates a new Catalog Item Role Object.
        
        .PARAMETER Policy
            Specify the Catalog Item Item Policy to be used
        
        .PARAMETER Path
            Specify the path of the Catalog Item.
        
        .PARAMETER TypeName
            Specity the type of the Catalog Item
        
        .PARAMETER ParentSecurity
            Specifies if the Security is set to the parent of the Catalog Item.

        .EXAMPLE
            $Proxy = New-RsWebServiceProxyHelper -BoundParameters $PSBoundParameters
            $Policies = $Proxy.GetPolicies("/", [ref]$True)
            New-RsCatalogItemRoleObject -Policy $Policies -Path "/" -TypeName "Folder"

            Description
            -----------
            This command will retrieve and return WMI Object associated to the default instance (MSSQLSERVER) of SQL Server 2016 Reporting Services.
        

    #>


    [cmdletbinding()]
    param
    (
        [Parameter(Mandatory=$True)]
        [Object[]] $Policy,

        [Parameter(Mandatory=$True)]
        [String]$Path,

        [Parameter(Mandatory=$True)]
        [String]$TypeName,

        [Parameter(Mandatory=$True)]
        [Boolean]$ParentSecurity
    )
    $catalogItemRoles = @()

    $Policy | ForEach-Object {
    
        $catalogItemRole = New-Object -TypeName PSCustomObject
        $catalogItemRole | Add-Member -MemberType NoteProperty -Name Identity -Value $_.GroupUserName
        $catalogItemRole | Add-Member -MemberType NoteProperty -Name Path -Value $Path
        $catalogItemRole | Add-Member -MemberType NoteProperty -Name TypeName -Value $TypeName
        $catalogItemRole | Add-Member -MemberType NoteProperty -Name Roles -Value $_.Roles
        $catalogItemRole | Add-Member -MemberType NoteProperty -Name ParentSecurity -Value $ParentSecurity

        $catalogItemRoles += $catalogItemRole
    }

    return $catalogItemRoles
}