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

function Export-RsSubscriptionXml {
    <#
        .SYNOPSIS
            This script exports one or more subscriptions that have been retrieved via Get-RsSubscription.
        
        .DESCRIPTION
            This script exports subscriptions to an XML file using Export-CliXml with a -Depth of 3.
            Use Import-RsSubscriptionXml to later re-import the subscriptions as valid subscription objects
            for use with Set-RsSubscription to implement in SRSS.
                    
        .PARAMETER Path
            The path to save the XML formatted file that will contain the exported subscription/s.
        
        .PARAMETER Subscription
            One or more subscription objects, typically retrieved via Get-RsSubscription.

        .EXAMPLE
            Get-RsSubscription -path '/path/to/my/report' | Export-RsSubscriptionXml .\MySubscriptions.xml

            Description
            -----------
            This command will export the current set of subscriptions contained in '/path/to/my/report' to an
            XML file named MySubscriptions.xml.
    #>

        
    [cmdletbinding(SupportsShouldProcess = $true, ConfirmImpact = 'Medium')]
    param(
        [Parameter(Mandatory=$True,Position=0)]
        [string]
        $Path,

        [Parameter(Mandatory = $True, ValueFromPipeline=$true)]
        [object]
        $Subscription
    )

    Begin {
        $Subscriptions = @()
    }
    Process {
        $Subscriptions = $Subscriptions + $Subscription
    }
    End {
        
        if ($PSCmdlet.ShouldProcess($Path, "Exporting subscriptions")) 
        {
            Write-Verbose "Exporting subscriptions to $Path..."
            $Subscriptions | Export-Clixml $Path -Depth 3
        }
    }
}