Functions/Utilities/New-RsCatalogItemRoleObject.ps1

# 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 Roles
            Specify the Roles assigned to 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)]
        [Microsoft.PowerShell.Commands.NewWebserviceProxy.AutogeneratedTypes.WebServiceProxy1tserver_ReportService2010_asmx.Policy[]] $Policy,

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

        [Parameter(Mandatory=$True)]
        [String]$TypeName
    )
    $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

        $catalogItemRoles += $catalogItemRole
    }

    return $catalogItemRoles
}