├── .github ├── ISSUE_TEMPLATE.md └── PULL_REQUEST_TEMPLATE.md ├── Install.ps1 ├── License.md ├── README.md ├── ReportingServicesTools ├── Functions │ ├── Admin │ │ ├── Backup-RsEncryptionKey.ps1 │ │ ├── Initialize-Rs.ps1 │ │ ├── Register-RsPowerBI.ps1 │ │ ├── Rest │ │ │ └── Get-RsRestPublicServerSetting.ps1 │ │ ├── Restore-RsEncryptionKey.ps1 │ │ ├── Set-PbiRsUrlReservation.ps1 │ │ ├── Set-RsDatabase.ps1 │ │ ├── Set-RsDatabaseCredentials.ps1 │ │ ├── Set-RsEmailSettings.ps1 │ │ └── Set-RsUrlReservation.ps1 │ ├── CatalogItems │ │ ├── Copy-RsSubscription.ps1 │ │ ├── Export-RsSubscriptionXml.ps1 │ │ ├── Get-RsDataSource.ps1 │ │ ├── Get-RsDeploymentConfig.ps1 │ │ ├── Get-RsFolderContent.ps1 │ │ ├── Get-RsItemDataSource.ps1 │ │ ├── Get-RsItemReference.ps1 │ │ ├── Get-RsSubscription.ps1 │ │ ├── Import-RsSubscriptionXml.ps1 │ │ ├── New-RsDataSource.ps1 │ │ ├── New-RsFolder.ps1 │ │ ├── New-RsScheduleXML.ps1 │ │ ├── New-RsSubscription.ps1 │ │ ├── Out-RsCatalogItem.ps1 │ │ ├── Out-RsFolderContent.ps1 │ │ ├── Publish-RsProject.ps1 │ │ ├── Remove-RsCatalogItem.ps1 │ │ ├── Remove-RsSubscription.ps1 │ │ ├── Rest │ │ │ ├── Get-RsRestCacheRefreshPlan.ps1 │ │ │ ├── Get-RsRestCacheRefreshPlanHistory.ps1 │ │ │ ├── Get-RsRestDataSource.ps1 │ │ │ ├── Get-RsRestFolderContent.ps1 │ │ │ ├── Get-RsRestItem.ps1 │ │ │ ├── Get-RsRestItemDataModelParameters.ps1 │ │ │ ├── Get-RsRestItemDataSource.ps1 │ │ │ ├── New-RsRestCacheRefreshPlan.ps1 │ │ │ ├── New-RsRestCredentialsByUserObject.ps1 │ │ │ ├── New-RsRestCredentialsInServerObject.ps1 │ │ │ ├── New-RsRestFolder.ps1 │ │ │ ├── Out-RsRestCatalogItem.ps1 │ │ │ ├── Out-RsRestCatalogItemId.ps1 │ │ │ ├── Out-RsRestFolderContent.ps1 │ │ │ ├── Remove-RsRestCacheRefreshPlan.ps1 │ │ │ ├── Remove-RsRestCatalogItem.ps1 │ │ │ ├── Remove-RsRestFolder.ps1 │ │ │ ├── Set-RsRestItemDataModelParameters.ps1 │ │ │ ├── Set-RsRestItemDataSource.ps1 │ │ │ ├── Start-RsRestCacheRefreshPlan.ps1 │ │ │ ├── Test-RsRestItemDataSource.ps1 │ │ │ ├── Write-RsRestCatalogItem.ps1 │ │ │ └── Write-RsRestFolderContent.ps1 │ │ ├── Set-RsDataSetReference.ps1 │ │ ├── Set-RsDataSource.ps1 │ │ ├── Set-RsDataSourcePassword.ps1 │ │ ├── Set-RsDataSourceReference.ps1 │ │ ├── Set-RsItemDataSource.ps1 │ │ ├── Set-RsSubscription.ps1 │ │ ├── Write-RsCatalogItem.ps1 │ │ └── Write-RsFolderContent.ps1 │ ├── Common │ │ ├── ConnectionObjectRequests.ps1 │ │ ├── Get-FileExtension.ps1 │ │ ├── Get-ItemType.ps1 │ │ ├── MakeDeploymentFolders.ps1 │ │ ├── New-RestSessionHelperSplat.ps1 │ │ ├── ShouldProcess.ps1 │ │ └── StringManipulation.ps1 │ ├── Security │ │ ├── Get-RsCatalogItemRole.ps1 │ │ ├── Grant-RsCatalogItemRole.ps1 │ │ ├── Grant-RsSystemRole.ps1 │ │ ├── Rest │ │ │ ├── Get-RsRestItemAccessPolicy.ps1 │ │ │ ├── Grant-RsRestItemAccessPolicy.ps1 │ │ │ └── Revoke-RsRestItemAccessPolicy.ps1 │ │ ├── Revoke-RsCatalogItemAccess.ps1 │ │ └── Revoke-RsSystemAccess.ps1 │ └── Utilities │ │ ├── Connect-RsReportServer.ps1 │ │ ├── New-RsCatalogItemRoleObject.ps1 │ │ ├── New-RsConfigurationSettingObject.ps1 │ │ ├── New-RsRestSession.ps1 │ │ └── New-RsWebServiceProxy.ps1 ├── Libraries │ └── library.ps1 ├── ReportingServicesTools.psd1 └── ReportingServicesTools.psm1 ├── SECURITY.md ├── Templates └── ScriptTemplate.ps1 ├── Test.ps1 ├── Tests ├── Admin │ ├── Rest │ │ └── Get-RsRestPublicServerSetting.Tests.ps1 │ ├── RsEncryptionKey.Tests.ps1 │ ├── Set-RsDatabase.Tests.ps1 │ └── Set-RsDatabaseCredentials.Tests.ps1 ├── CatalogItems │ ├── Copy-RsSubscription.Tests.ps1 │ ├── Export-RsSubscriptionXml.Tests.ps1 │ ├── Get-RsDataSource.Tests.ps1 │ ├── Get-RsDeploymentConfig.Tests.ps1 │ ├── Get-RsFolderContentTests.ps1 │ ├── Get-RsItemDataSource.Tests.ps1 │ ├── Get-RsItemReference.Tests.ps1 │ ├── Get-RsSubscription.Tests.ps1 │ ├── Import-RsSubscriptionXml.Tests.ps1 │ ├── New-RsDataSource.Tests.ps1 │ ├── New-RsFolder.Tests.ps1 │ ├── New-RsScheduleXML.Tests.ps1 │ ├── New-RsSubscription.Tests.ps1 │ ├── Out-RsCatalogItem.Tests.ps1 │ ├── Out-RsFolderContent.Tests.ps1 │ ├── Publish-RsProject.Test.ps1 │ ├── Remove-RsCatalogItem.Tests.ps1 │ ├── Remove-RsSubscription.Tests.ps1 │ ├── Rest │ │ ├── Get-RsRestCacheRefreshPlan.Tests.ps1 │ │ ├── Get-RsRestCacheRefreshPlanHistory.Tests.ps1 │ │ ├── Get-RsRestDataSource.Tests.ps1 │ │ ├── Get-RsRestFolderContent.Tests.ps1 │ │ ├── Get-RsRestItem.Tests.ps1 │ │ ├── Get-RsRestItemDataModelParameters.Tests.ps1 │ │ ├── Get-RsRestItemDataSource.Tests.ps1 │ │ ├── New-RsRestCacheRefreshPlan.Tests.ps1 │ │ ├── New-RsRestFolder.Tests.ps1 │ │ ├── Out-RsRestCatalogItem.Tests.ps1 │ │ ├── Out-RsRestFolderContent.Tests.ps1 │ │ ├── Remove-RsRestCacheRefreshPlan.Tests.ps1 │ │ ├── Remove-RsRestCatalogItem.Tests.ps1 │ │ ├── Remove-RsRestFolder.Tests.ps1 │ │ ├── Set-RsRestItemDataModelParameters.Tests.ps1 │ │ ├── Set-RsRestItemDataSource.Tests.ps1 │ │ ├── Start-RsRestCacheRefreshPlan.Tests.ps1 │ │ ├── Test-RsRestItemDataSource.Tests.ps1 │ │ ├── Write-RsRestCatalogItem.Tests.ps1 │ │ └── Write-RsRestFolderContent.Tests.ps1 │ ├── Set-RsDataSetReference.Tests.ps1 │ ├── Set-RsDataSource.Tests.ps1 │ ├── Set-RsItemDataSource.Tests.ps1 │ ├── Set-RsSubscription.Tests.ps1 │ ├── TestProjects │ │ └── SQLServerPerformanceDashboardReportingSolution │ │ │ ├── PerfDashboard.sln │ │ │ └── SQL Server Performance Dashboard │ │ │ ├── SQL Server Performance Dashboard.rptproj │ │ │ ├── database_overview.rdl │ │ │ ├── database_storage_report.rdl │ │ │ ├── historical_io.rdl │ │ │ ├── historical_waits.rdl │ │ │ ├── missing_index_from_showplan.rdl │ │ │ ├── missing_indexes.rdl │ │ │ ├── page_details.rdl │ │ │ ├── performance_dashboard_main.rdl │ │ │ ├── plan_guide.rdl │ │ │ ├── query_plan.rdl │ │ │ ├── query_stats.rdl │ │ │ ├── query_stats_details.rdl │ │ │ ├── recent_cpu.rdl │ │ │ ├── requests_overview.rdl │ │ │ ├── session_details.rdl │ │ │ ├── sessions_overview.rdl │ │ │ ├── traces.rdl │ │ │ ├── wait_blocking.rdl │ │ │ ├── wait_buffer_io.rdl │ │ │ ├── wait_buflatch.rdl │ │ │ ├── wait_generic.rdl │ │ │ └── wait_latch.rdl │ ├── Write-RsCatalogItem.Tests.ps1 │ ├── Write-RsFolderContent.Tests.ps1 │ └── testResources │ │ ├── DataModelParameters.pbix │ │ ├── NewExcelWorkbook.xlsx │ │ ├── NewKPI.kpi │ │ ├── OldExcelWorkbook.xls │ │ ├── ReportCatalog.pbix │ │ ├── SimplePowerBIReport.pbix │ │ ├── SqlPowerBIReport.pbix │ │ ├── SutWriteRsFolderContent_DataSource.rsds │ │ ├── UnDataset.rsd │ │ ├── datasources │ │ ├── datasourcesReport.rdl │ │ └── noDatasourcesReport.rdl │ │ ├── emptyFile.txt │ │ ├── emptyReport.rdl │ │ ├── imagesResources │ │ ├── PowerShellHero.jpg │ │ └── SSRS.png │ │ ├── linkedDatasources │ │ ├── datasourcesReportLinkedDS.rdl │ │ ├── dsMaster.rsds │ │ └── dsModel.rsds │ │ └── testResources2 │ │ └── emptyReport2.rdl ├── Security │ ├── AccessOnCatalogItem.Tests.ps1 │ ├── AccessToRs.Tests.ps1 │ ├── Get-RsCatalogItemRole.Tests.ps1 │ └── Rest │ │ ├── AccessPolicyOnRsRestItem.Tests.ps1 │ │ └── Get-RsRestItemAccessPolicy.Tests.ps1 └── Utilities │ └── NewRsRestSessionTests.ps1 └── appveyor.yml /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | **Do you want to request a *feature* or report a *bug*?** 2 | 3 | **What is the current behavior?** 4 | 5 | **If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem.** 6 | 7 | **What is the expected behavior?** 8 | 9 | **Which versions of Powershell and which OS are affected by this issue? Did this work in previous versions of our scripts?** 10 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Fixes # . 2 | 3 | Changes proposed in this pull request: 4 | - 5 | - 6 | - 7 | 8 | How to test this code: 9 | - 10 | - 11 | - 12 | 13 | Has been tested on (remove any that don't apply): 14 | - Powershell 3 and above 15 | - Windows 7 and above 16 | - SQL Server 2012 and above 17 | -------------------------------------------------------------------------------- /Install.ps1: -------------------------------------------------------------------------------- 1 | [CmdletBinding()] 2 | param ( 3 | [string]$Path, 4 | [string]$Version = 'master' 5 | ) 6 | 7 | $localpath = $(Join-Path -Path (Split-Path -Path $profile) -ChildPath '\Modules\ReportingServicesTools') 8 | 9 | try 10 | { 11 | if ($Path.length -eq 0) 12 | { 13 | if ($PSCommandPath.Length -gt 0) 14 | { 15 | $path = Split-Path $PSCommandPath 16 | if ($path -match "github") 17 | { 18 | $path = $localpath 19 | } 20 | } 21 | else 22 | { 23 | $path = $localpath 24 | } 25 | } 26 | } 27 | catch 28 | { 29 | $path = $localpath 30 | } 31 | 32 | if ($path.length -eq 0) 33 | { 34 | $path = $localpath 35 | } 36 | 37 | if ((Get-Command -Module ReportingServicesTools).count -ne 0) 38 | { 39 | Write-Output "Removing existing ReportingServiceTools Module..." 40 | Remove-Module ReportingServicesTools -ErrorAction Stop 41 | } 42 | 43 | $url = "https://github.com/Microsoft/ReportingServicesTools/archive/$Version.zip" 44 | 45 | $temp = ([System.IO.Path]::GetTempPath()).TrimEnd("\") 46 | $zipfile = "$temp\ReportingServicesTools.zip" 47 | 48 | if (!(Test-Path -Path $path)) 49 | { 50 | try 51 | { 52 | Write-Output "Creating directory: $path..." 53 | New-Item -Path $path -ItemType Directory | Out-Null 54 | } 55 | catch 56 | { 57 | throw "Can't create $Path. You may need to Run as Administrator!" 58 | } 59 | } 60 | else 61 | { 62 | try 63 | { 64 | Write-Output "Deleting previously installed module..." 65 | Remove-Item -Path "$path\*" -Force -Recurse 66 | } 67 | catch 68 | { 69 | throw "Can't delete $Path. You may need to Run as Administrator!" 70 | } 71 | } 72 | 73 | Write-Output "Downloading archive from ReportingServiceTools GitHub..." 74 | [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 75 | try 76 | { 77 | Invoke-WebRequest $url -OutFile $zipfile 78 | } 79 | catch 80 | { 81 | #try with default proxy and usersettings 82 | Write-Output "...Probably using a proxy for internet access. Trying default proxy settings..." 83 | (New-Object System.Net.WebClient).Proxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials 84 | Invoke-WebRequest $url -OutFile $zipfile -ErrorAction Stop 85 | } 86 | 87 | # Unblock if there's a block 88 | Unblock-File $zipfile -ErrorAction SilentlyContinue 89 | 90 | # Keep it backwards compatible 91 | Write-Output "Unzipping archive..." 92 | $shell = New-Object -COM Shell.Application 93 | $zipPackage = $shell.NameSpace($zipfile) 94 | $destinationFolder = $shell.NameSpace($temp) 95 | $destinationFolder.CopyHere($zipPackage.Items()) 96 | Move-Item -Path "$temp\ReportingServicesTools-$Version\*" $path 97 | Write-Output "ReportingServicesTools has been successfully downloaded to $path!" 98 | 99 | Write-Output "Cleaning up..." 100 | Remove-Item -Path "$temp\ReportingServicesTools-$Version" 101 | Remove-Item -Path $zipfile 102 | 103 | Write-Output "Importing ReportingServicesTools Module..." 104 | Import-Module "$path\ReportingServicesTools\ReportingServicesTools.psd1" -Force 105 | Write-Output "ReportingServicesTools Module was successfully imported!" 106 | 107 | Get-Command -Module ReportingServicesTools 108 | Write-Output "`n`nIf you experience any function missing errors after update, please restart PowerShell or reload your profile." 109 | -------------------------------------------------------------------------------- /License.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Microsoft 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /ReportingServicesTools/Functions/Admin/Backup-RsEncryptionKey.ps1: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2016 Microsoft Corporation. All Rights Reserved. 2 | # Licensed under the MIT License (MIT) 3 | 4 | function Backup-RsEncryptionKey 5 | { 6 | <# 7 | .SYNOPSIS 8 | This script creates a back up of the SQL Server Reporting Services encryption key. 9 | 10 | .DESCRIPTION 11 | This script creates a back up of the encryption key for SQL Server Reporting Services. This key is needed in order to read all the encrypted content stored in the Reporting Services Catalog database. 12 | 13 | .PARAMETER Password 14 | Specify the password to be used for backing up the encryption key. This password will be required when restoring the encryption key. 15 | 16 | .PARAMETER KeyPath 17 | Specify the path to where the encryption key should be stored. 18 | 19 | .PARAMETER ReportServerInstance 20 | Specify the name of the SQL Server Reporting Services Instance. 21 | Use the "Connect-RsReportServer" function to set/update a default value. 22 | 23 | .PARAMETER ReportServerVersion 24 | Specify the version of the SQL Server Reporting Services Instance. 25 | Use the "Connect-RsReportServer" function to set/update a default value. 26 | 27 | .PARAMETER ComputerName 28 | The Report Server to target. 29 | Use the "Connect-RsReportServer" function to set/update a default value. 30 | 31 | .PARAMETER Credential 32 | Specify the credentials to use when connecting to the Report Server. 33 | Use the "Connect-RsReportServer" function to set/update a default value. 34 | 35 | .EXAMPLE 36 | Backup-RSEncryptionKey -Password 'Enter Your Password' -KeyPath 'C:\ReportingServices\Default.snk' 37 | Description 38 | ----------- 39 | This command will back up the encryption key against default instance from SQL Server 2016 Reporting Services 40 | 41 | .EXAMPLE 42 | Backup-RSEncryptionKey -ReportServerInstance 'SQL2012' -ReportServerVersion '11' -Password 'Enter Your Password' -KeyPath 'C:\ReportingServices\Default.snk' 43 | Description 44 | ----------- 45 | This command will back up the encryption key against named instance (SQL2012) from SQL Server 2012 Reporting Services 46 | 47 | .EXAMPLE 48 | Backup-RSEncryptionKey -ComputerName "sql2012a243" -Credential (Get-Credential) -ReportServerInstance 'SQL2012' -ReportServerVersion 'SQLServer2012' -Password 'Enter Your Password' -KeyPath 'C:\ReportingServices\Default.snk' 49 | Description 50 | ----------- 51 | This command will back up the encryption key against named instance (SQL2012) from SQL Server 2012 Reporting Services. 52 | To do so, it will not use the default connection, but rather connect to the computer "sql2012a243", prompting the user for connection credentials. 53 | #> 54 | 55 | [CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'Medium')] 56 | param 57 | ( 58 | [Parameter(Mandatory = $True)] 59 | [string] 60 | $Password, 61 | 62 | [Parameter(Mandatory = $True)] 63 | [string] 64 | $KeyPath, 65 | 66 | [Alias('SqlServerInstance')] 67 | [string] 68 | $ReportServerInstance, 69 | 70 | [Alias('SqlServerVersion')] 71 | [Microsoft.ReportingServicesTools.SqlServerVersion] 72 | $ReportServerVersion, 73 | 74 | [string] 75 | $ComputerName, 76 | 77 | [System.Management.Automation.PSCredential] 78 | $Credential 79 | ) 80 | 81 | if ($PSCmdlet.ShouldProcess((Get-ShouldProcessTargetWmi -BoundParameters $PSBoundParameters), "Retrieve encryption key and create backup in $KeyPath")) 82 | { 83 | $rsWmiObject = New-RsConfigurationSettingObjectHelper -BoundParameters $PSBoundParameters 84 | 85 | Write-Verbose "Retrieving encryption key..." 86 | $encryptionKeyResult = $rsWmiObject.BackupEncryptionKey($Password) 87 | 88 | if ($encryptionKeyResult.HRESULT -eq 0) 89 | { 90 | Write-Verbose "Retrieving encryption key... Success!" 91 | } 92 | else 93 | { 94 | throw "Failed to create backup of the encryption key. Errors: $($encryptionKeyResult.ExtendedErrors)" 95 | } 96 | 97 | try 98 | { 99 | Write-Verbose "Writing key to file..." 100 | [System.IO.File]::WriteAllBytes($KeyPath, $encryptionKeyResult.KeyFile) 101 | Write-Verbose "Writing key to file... Success!" 102 | } 103 | catch 104 | { 105 | throw 106 | } 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /ReportingServicesTools/Functions/Admin/Initialize-Rs.ps1: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2016 Microsoft Corporation. All Rights Reserved. 2 | # Licensed under the MIT License (MIT) 3 | 4 | function Initialize-Rs 5 | { 6 | <# 7 | .SYNOPSIS 8 | This command initializes an instance of Report Server after the database and urls have been configured. 9 | 10 | .DESCRIPTION 11 | This command initializes an instance of Report Server after the database and urls have been configured. 12 | 13 | .PARAMETER ReportServerInstance 14 | Specify the name of the SQL Server Reporting Services Instance. 15 | Use the "Connect-RsReportServer" function to set/update a default value. 16 | 17 | .PARAMETER ReportServerVersion 18 | Specify the version of the SQL Server Reporting Services Instance. 19 | Use the "Connect-RsReportServer" function to set/update a default value. 20 | 21 | .PARAMETER ComputerName 22 | The Report Server to target. 23 | Use the "Connect-RsReportServer" function to set/update a default value. 24 | 25 | .PARAMETER Credential 26 | Specify the credentials to use when connecting to the Report Server. 27 | Use the "Connect-RsReportServer" function to set/update a default value. 28 | 29 | .EXAMPLE 30 | Initialize-Rs 31 | Description 32 | ----------- 33 | This command will initialize the Report Server 34 | #> 35 | 36 | [cmdletbinding()] 37 | param 38 | ( 39 | 40 | [Alias('SqlServerInstance')] 41 | [string] 42 | $ReportServerInstance, 43 | 44 | [Alias('SqlServerVersion')] 45 | [Microsoft.ReportingServicesTools.SqlServerVersion] 46 | $ReportServerVersion, 47 | 48 | [string] 49 | $ComputerName, 50 | 51 | [System.Management.Automation.PSCredential] 52 | $Credential 53 | ) 54 | 55 | $rsWmiObject = New-RsConfigurationSettingObjectHelper -BoundParameters $PSBoundParameters 56 | 57 | try 58 | { 59 | Write-Verbose "Initializing Report Server..." 60 | $result = $rsWmiObject.InitializeReportServer($rsWmiObject.InstallationID) 61 | Write-Verbose "Success!" 62 | } 63 | catch 64 | { 65 | throw (New-Object System.Exception("Failed to Initialize Report Server $($_.Exception.Message)", $_.Exception)) 66 | } 67 | 68 | if ($result.HRESULT -ne 0) 69 | { 70 | throw "Failed to Initialize Report Server, ErrorCode: $($result.HRESULT)" 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /ReportingServicesTools/Functions/Admin/Rest/Get-RsRestPublicServerSetting.ps1: -------------------------------------------------------------------------------- 1 | function Get-RsRestPublicServerSetting 2 | { 3 | <# 4 | .SYNOPSIS 5 | This function gets the public settings of the RS server. 6 | 7 | .DESCRIPTION 8 | This function gets the value of the specified property from the public settings of the RS server. 9 | 10 | .PARAMETER Property 11 | Specify the name of the property. 12 | 13 | .PARAMETER ReportPortalUri 14 | Specify the Report Portal URL to your SQL Server Reporting Services Instance. 15 | 16 | .PARAMETER RestApiVersion 17 | Specify the version of REST Endpoint to use. Valid values are: "v2.0". 18 | 19 | .PARAMETER Credential 20 | Specify the credentials to use when connecting to the Report Server. 21 | 22 | .PARAMETER WebSession 23 | Specify the session to be used when making calls to REST Endpoint. 24 | 25 | .EXAMPLE 26 | Get-RsRestPublicServerSetting -Property "MaxFileSizeMb" 27 | Description 28 | ----------- 29 | Gets the value of the property "MaxFileSizeMb" from the Report Server located at http://localhost/reports. 30 | #> 31 | 32 | [CmdletBinding()] 33 | param 34 | ( 35 | [Parameter(Mandatory = $True)] 36 | [string] 37 | $Property, 38 | 39 | [string] 40 | $ReportPortalUri, 41 | 42 | [Alias('ApiVersion')] 43 | [ValidateSet("v2.0")] 44 | [string] 45 | $RestApiVersion = "v2.0", 46 | 47 | [Alias('ReportServerCredentials')] 48 | [System.Management.Automation.PSCredential] 49 | $Credential, 50 | 51 | [Microsoft.PowerShell.Commands.WebRequestSession] 52 | $WebSession 53 | ) 54 | Begin 55 | { 56 | $WebSession = New-RsRestSessionHelper -BoundParameters $PSBoundParameters 57 | if ($null -ne $WebSession.Credentials -and $null -eq $Credential) { 58 | Write-Verbose "Using credentials from WebSession" 59 | $Credential = New-Object System.Management.Automation.PSCredential "$($WebSession.Credentials.UserName)@$($WebSession.Credentials.Domain)", $WebSession.Credentials.SecurePassword 60 | } 61 | $ReportPortalUri = Get-RsPortalUriHelper -WebSession $WebSession 62 | $systemPropertiesUri = $ReportPortalUri + "api/$RestApiVersion/System/Properties?properties={0}" 63 | } 64 | Process 65 | { 66 | try 67 | { 68 | Write-Verbose "Getting server configuration - $Property" 69 | 70 | $uri = [String]::Format($systemPropertiesUri, $Property) 71 | 72 | if ($Credential -ne $null) 73 | { 74 | $response = Invoke-RestMethod -Uri $uri -Method Get -WebSession $WebSession -Credential $Credential -Verbose:$false 75 | } 76 | else 77 | { 78 | $response = Invoke-RestMethod -Uri $uri -Method Get -WebSession $WebSession -UseDefaultCredentials -Verbose:$false 79 | } 80 | 81 | if ($response -ne $null -and $response.value -ne $null -and $response.value[0] -ne $null -and $response.value[0].Name -eq $Property) 82 | { 83 | return $response.value[0].Value 84 | } 85 | else 86 | { 87 | return $null 88 | } 89 | } 90 | catch 91 | { 92 | Write-Error (New-Object System.Exception("Failed to get server setting: $($_.Exception.Message)", $_.Exception)) 93 | } 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /ReportingServicesTools/Functions/Admin/Set-PbiRsUrlReservation.ps1: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2016 Microsoft Corporation. All Rights Reserved. 2 | # Licensed under the MIT License (MIT) 3 | 4 | function Set-PbiRsUrlReservation 5 | { 6 | <# 7 | .SYNOPSIS 8 | This command configures the urls for PBI Report Server 9 | 10 | .DESCRIPTION 11 | This command configures the urls for PBI Report Server 12 | 13 | .PARAMETER ReportServerVirtualDirectory 14 | Specify the name of the virtual directory for the Report Server Endpoint the default is ReportServer, it will configure it as http://myMachine/reportserver 15 | 16 | .PARAMETER PortalVirtualDirectory 17 | Specify the name of the virtual directory for the Portal Endpoint the default is ReportServer, it will configure it as http://myMachine/reports 18 | 19 | .PARAMETER ReportServerInstance 20 | Specify the name of the SQL Server Reporting Services Instance. 21 | Use the "Connect-RsReportServer" function to set/update a default value. 22 | 23 | .PARAMETER ReportServerVersion 24 | Specify the version of the SQL Server Reporting Services Instance. 25 | Use the "Connect-RsReportServer" function to set/update a default value. 26 | 27 | .PARAMETER ComputerName 28 | The Report Server to target. 29 | Use the "Connect-RsReportServer" function to set/update a default value. 30 | 31 | .PARAMETER Credential 32 | The credentials with which to connect to the Report Server. 33 | Use the "Connect-RsReportServer" function to set/update a default value. 34 | 35 | .PARAMETER ListeningPort 36 | Specify the Listening Port 37 | 38 | .EXAMPLE 39 | Set-PbiRsUrlReservation 40 | Description 41 | ----------- 42 | This command will configure the Report Server with the default urls http://myMachine/ReportServer and http://myMachine/Reports 43 | 44 | .EXAMPLE 45 | Set-PbiRsUrlReservation -ReportServerVirtualDirectory ReportServer2017 -PortalVirtualDirectory Reports2017 46 | Description 47 | ----------- 48 | This command will configure the url for the server with http://myMachine/ReportServer2017 and http://myMachine/Reports2017 49 | 50 | .EXAMPLE 51 | Set-PbiRsUrlReservation -ReportServerVirtualDirectory ReportServer2017 -PortalVirtualDirectory Reports2017 -ListeningPort 8080 52 | Description 53 | ----------- 54 | This command will configure the url for the server with http://myMachine:8080/ReportServer2017 and http://myMachine:8080/Reports2017 55 | #> 56 | 57 | [cmdletbinding()] 58 | param 59 | ( 60 | [string] 61 | $ReportServerVirtualDirectory = "ReportServer", 62 | 63 | [string] 64 | $PortalVirtualDirectory="Reports", 65 | 66 | [Alias('SqlServerInstance')] 67 | [string] 68 | $ReportServerInstance, 69 | 70 | [Alias('SqlServerVersion')] 71 | [Microsoft.ReportingServicesTools.SqlServerVersion] 72 | $ReportServerVersion, 73 | 74 | [string] 75 | $ComputerName, 76 | 77 | [System.Management.Automation.PSCredential] 78 | $Credential, 79 | 80 | [int] 81 | $ListeningPort=80 82 | ) 83 | 84 | $pbirsWmiObject = New-RsConfigurationSettingObjectHelper -BoundParameters $PSBoundParameters 85 | 86 | try 87 | { 88 | Set-RsUrlReservation -ReportServerVirtualDirectory $ReportServerVirtualDirectory -PortalVirtualDirectory $PortalVirtualDirectory -ReportServerInstance $ReportServerInstance -ReportServerVersion $ReportServerVersion -ComputerName $ComputerName -Credential $Credential -ListeningPort $ListeningPort 89 | 90 | $powerBiApp = "PowerBIWebApp" 91 | Write-Verbose "Reserving Url for $powerBiApp..." 92 | $result = $pbirsWmiObject.ReserveURL($powerBiApp,"http://+:$ListeningPort",(Get-Culture).Lcid) 93 | 94 | if ($result.HRESULT -ne 0) 95 | { 96 | throw "Failed Reserving Url for $powerBiApp, Errocode: $($result.HRESULT)" 97 | } 98 | 99 | $officeWebApp = "OfficeWebApp" 100 | Write-Verbose "Reserving Url for $officeWebApp..." 101 | $result = $pbirsWmiObject.ReserveURL($officeWebApp,"http://+:$ListeningPort",(Get-Culture).Lcid) 102 | 103 | if ($result.HRESULT -ne 0) 104 | { 105 | throw "Failed Reserving Url for $officeWebApp, Errocode: $($result.HRESULT)" 106 | } 107 | 108 | Write-Verbose "Success!" 109 | } 110 | catch 111 | { 112 | throw (New-Object System.Exception("Failed to reserve Urls $($_.Exception.Message)", $_.Exception)) 113 | } 114 | 115 | if ($result.HRESULT -ne 0) 116 | { 117 | throw "Failed to reserve Urls, Errocode: $($result.HRESULT)" 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /ReportingServicesTools/Functions/CatalogItems/Export-RsSubscriptionXml.ps1: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2016 Microsoft Corporation. All Rights Reserved. 2 | # Licensed under the MIT License (MIT) 3 | 4 | function Export-RsSubscriptionXml { 5 | <# 6 | .SYNOPSIS 7 | This script exports one or more subscriptions that have been retrieved via Get-RsSubscription. 8 | 9 | .DESCRIPTION 10 | This script exports subscriptions to an XML file using Export-CliXml with a -Depth of 3. 11 | Use Import-RsSubscriptionXml to later re-import the subscriptions as valid subscription objects 12 | for use with Set-RsSubscription to implement in SRSS. 13 | 14 | .PARAMETER Path 15 | The path to save the XML formatted file that will contain the exported subscription/s. 16 | 17 | .PARAMETER Subscription 18 | One or more subscription objects, typically retrieved via Get-RsSubscription. 19 | 20 | .EXAMPLE 21 | Get-RsSubscription -path '/path/to/my/report' | Export-RsSubscriptionXml .\MySubscriptions.xml 22 | 23 | Description 24 | ----------- 25 | This command will export the current set of subscriptions contained in '/path/to/my/report' to an 26 | XML file named MySubscriptions.xml. 27 | #> 28 | 29 | [cmdletbinding(SupportsShouldProcess = $true, ConfirmImpact = 'Medium')] 30 | param( 31 | [Parameter(Mandatory=$True,Position=0)] 32 | [string] 33 | $Path, 34 | 35 | [Parameter(Mandatory = $True, ValueFromPipeline=$true)] 36 | [object] 37 | $Subscription 38 | ) 39 | 40 | Begin { 41 | $Subscriptions = @() 42 | } 43 | Process { 44 | $Subscriptions = $Subscriptions + $Subscription 45 | } 46 | End { 47 | 48 | if ($PSCmdlet.ShouldProcess($Path, "Exporting subscriptions")) 49 | { 50 | Write-Verbose "Exporting subscriptions to $Path..." 51 | $Subscriptions | Export-Clixml $Path -Depth 3 52 | } 53 | } 54 | } -------------------------------------------------------------------------------- /ReportingServicesTools/Functions/CatalogItems/Get-RsDataSource.ps1: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2016 Microsoft Corporation. All Rights Reserved. 2 | # Licensed under the MIT License (MIT) 3 | 4 | function Get-RsDataSource 5 | { 6 | <# 7 | .SYNOPSIS 8 | This script retrieves information about data source on Report Server. 9 | 10 | .DESCRIPTION 11 | This script retrieves information about data source found at the specified location on Report Server. 12 | 13 | .PARAMETER Path 14 | Specify the path to the data source. 15 | 16 | .PARAMETER ReportServerUri 17 | Specify the Report Server URL to your SQL Server Reporting Services Instance. 18 | Use the "Connect-RsReportServer" function to set/update a default value. 19 | 20 | .PARAMETER Credential 21 | Specify the credentials to use when connecting to the Report Server. 22 | Use the "Connect-RsReportServer" function to set/update a default value. 23 | 24 | .PARAMETER Proxy 25 | Report server proxy to use. 26 | Use "New-RsWebServiceProxy" to generate a proxy object for reuse. 27 | Useful when repeatedly having to connect to multiple different Report Server. 28 | 29 | .EXAMPLE 30 | Get-RsDataSource -Path '/path/to/my/datasource' 31 | Description 32 | ----------- 33 | This command will establish a connection to the Report Server located at http://localhost/reportserver using current user's credentials and retrieve details of data source found at '/path/to/my/datasource'. 34 | 35 | .EXAMPLE 36 | Get-RsDataSource -ReportServerUri 'http://remote-machine:8080/reportserver_sql16' -Path '/path/to/my/datasource' 37 | Description 38 | ----------- 39 | This command will establish a connection to the Report Server located at http://remote-machine:8080/reportserver_sql16 using current user's credentials and retrieve details of data source found at '/path/to/my/datasource'. 40 | 41 | .EXAMPLE 42 | $rsProxy = New-RsWebServiceProxy -ReportServerUri 'http://remote-machine:8080/reportserver_sql16' 43 | Get-RsDataSource -Proxy $rsProxy -Path '/path/to/my/datasource' 44 | Description 45 | ----------- 46 | This command will establish a connection to the Report Server located at $rsProxy using current user's credentials and retrieve details of data source found at '/path/to/my/datasource'. 47 | #> 48 | 49 | [cmdletbinding()] 50 | param 51 | ( 52 | [Alias('ItemPath', 'DataSourcePath')] 53 | [Parameter(Mandatory = $True, ValueFromPipeline = $true)] 54 | [string[]] 55 | $Path, 56 | 57 | [string] 58 | $ReportServerUri, 59 | 60 | [Alias('ReportServerCredentials')] 61 | [System.Management.Automation.PSCredential] 62 | $Credential, 63 | 64 | $Proxy 65 | ) 66 | 67 | Begin 68 | { 69 | $Proxy = New-RsWebServiceProxyHelper -BoundParameters $PSBoundParameters 70 | } 71 | Process 72 | { 73 | foreach ($Item in $Path) 74 | { 75 | try 76 | { 77 | Write-Verbose "Retrieving data source contents..." 78 | $Proxy.GetDataSourceContents($Item) 79 | Write-Verbose "Data source retrieved successfully!" 80 | } 81 | catch 82 | { 83 | throw (New-Object System.Exception("Exception while retrieving datasource! $($_.Exception.Message)", $_.Exception)) 84 | } 85 | } 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /ReportingServicesTools/Functions/CatalogItems/Get-RsFolderContent.ps1: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2016 Microsoft Corporation. All Rights Reserved. 2 | # Licensed under the MIT License (MIT) 3 | 4 | function Get-RsFolderContent 5 | { 6 | <# 7 | .SYNOPSIS 8 | List all catalog items under a given path. 9 | 10 | .DESCRIPTION 11 | List all catalog items under a given path. 12 | 13 | .PARAMETER RsFolder 14 | Path to folder on SSRS instance. 15 | 16 | .PARAMETER Recurse 17 | Recursively list subfolders with content. 18 | 19 | .PARAMETER ReportServerUri 20 | Specify the Report Server URL to your SQL Server Reporting Services Instance. 21 | Use the "Connect-RsReportServer" function to set/update a default value. 22 | 23 | .PARAMETER Credential 24 | Specify the credentials to use when connecting to the Report Server. 25 | Use the "Connect-RsReportServer" function to set/update a default value. 26 | 27 | .PARAMETER Proxy 28 | Report server proxy to use. 29 | Use "New-RsWebServiceProxy" to generate a proxy object for reuse. 30 | Useful when repeatedly having to connect to multiple different Report Server. 31 | 32 | .EXAMPLE 33 | Get-RsFolderContent -ReportServerUri 'http://localhost/reportserver_sql2012' -RsFolder / 34 | 35 | Description 36 | ----------- 37 | List all items under the root folder 38 | 39 | .EXAMPLE 40 | Get-RsFolderContent -ReportServerUri http://localhost/ReportServer -RsFolder / -Recurse 41 | 42 | Description 43 | ----------- 44 | Lists all items directly under the root of the SSRS instance and recursively under all sub-folders. 45 | 46 | .EXAMPLE 47 | Get-RsFolderContent -RsFolder '/SQL Server Performance Dashboard' | WHERE Name -Like Wait* | Out-RsCatalogItem -Destination c:\SQLReports 48 | 49 | Description 50 | ----------- 51 | Downloads all catalog items from folder '/SQL Server Performance Dashboard' with a name that starts with 'Wait' to folder 'C:\SQLReports'. 52 | #> 53 | 54 | [cmdletbinding()] 55 | param( 56 | [Alias('ItemPath', 'Path')] 57 | [Parameter(Mandatory = $True, ValueFromPipeline = $true)] 58 | [string[]] 59 | $RsFolder, 60 | 61 | [switch] 62 | $Recurse, 63 | 64 | [string] 65 | $ReportServerUri, 66 | 67 | [Alias('ReportServerCredentials')] 68 | [System.Management.Automation.PSCredential] 69 | $Credential, 70 | 71 | $Proxy 72 | ) 73 | 74 | Begin 75 | { 76 | $Proxy = New-RsWebServiceProxyHelper -BoundParameters $PSBoundParameters 77 | } 78 | 79 | Process 80 | { 81 | foreach ($item in $RsFolder) 82 | { 83 | try 84 | { 85 | $Proxy.ListChildren($Item, $Recurse) 86 | } 87 | catch 88 | { 89 | throw 90 | } 91 | } 92 | } 93 | } 94 | New-Alias -Name "Get-RsCatalogItems" -Value Get-RsFolderContent -Scope Global 95 | New-Alias -Name "Get-RsChildItem" -Value Get-RsFolderContent -Scope Global 96 | New-Alias -Name "rsdir" -Value Get-RsFolderContent -Scope Global 97 | -------------------------------------------------------------------------------- /ReportingServicesTools/Functions/CatalogItems/Get-RsItemDataSource.ps1: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2017 Microsoft Corporation. All Rights Reserved. 2 | # Licensed under the MIT License (MIT) 3 | 4 | function Get-RsItemDataSource 5 | { 6 | <# 7 | .SYNOPSIS 8 | This script retrieves embedded data sources for a report or a shared data set on Report Server. 9 | 10 | .DESCRIPTION 11 | This script retrieves embedded data sources for a report or a shared data set on Report Server. 12 | 13 | .PARAMETER RsItem 14 | Specify the path to report or shared data set. 15 | 16 | .PARAMETER ReportServerUri 17 | Specify the Report Server URL to your SQL Server Reporting Services Instance. 18 | Use the "Connect-RsReportServer" function to set/update a default value. 19 | 20 | .PARAMETER Credential 21 | Specify the credentials to use when connecting to the Report Server. 22 | Use the "Connect-RsReportServer" function to set/update a default value. 23 | 24 | .PARAMETER Proxy 25 | Report server proxy to use. 26 | Use "New-RsWebServiceProxy" to generate a proxy object for reuse. 27 | Useful when repeatedly having to connect to multiple different Report Server. 28 | 29 | .EXAMPLE 30 | Get-RsItemDataSource -RsItem '/report' 31 | 32 | Description 33 | ----------- 34 | This command will fetch data sources associated to '/report' catalog item from the Report Server located at http://localhost/reportserver. 35 | 36 | .EXAMPLE 37 | Get-RsItemDataSource -ReportServerUri 'http://remote-machine:8080/reportserver_sql16' -RsItem '/report 38 | 39 | Description 40 | ----------- 41 | This command will fetch data sources associated to '/report' catalog item from the Report Server located at http://remote-machine:8080/reportserver_sql16. 42 | 43 | .EXAMPLE 44 | $rsProxy = New-RsWebServiceProxy (...) 45 | Get-RsItemDataSource -Proxy $rsProxy -RsItem '/report 46 | 47 | Description 48 | ----------- 49 | This command will fetch data sources associated to '/report' catalog item from the Report Server located at $rsProxy. 50 | #> 51 | 52 | [cmdletbinding()] 53 | param 54 | ( 55 | [Alias('ItemPath', 'DataSourcePath', 'Path')] 56 | [Parameter(Mandatory = $True, ValueFromPipeline = $true)] 57 | [string] 58 | $RsItem, 59 | 60 | [string] 61 | $ReportServerUri, 62 | 63 | [Alias('ReportServerCredentials')] 64 | [System.Management.Automation.PSCredential] 65 | $Credential, 66 | 67 | $Proxy 68 | ) 69 | 70 | Begin 71 | { 72 | $Proxy = New-RsWebServiceProxyHelper -BoundParameters $PSBoundParameters 73 | } 74 | Process 75 | { 76 | try 77 | { 78 | Write-Verbose "Retrieving data sources associated to $RsItem..." 79 | $Proxy.GetItemDataSources($RsItem) 80 | Write-Verbose "Data source retrieved successfully!" 81 | } 82 | catch 83 | { 84 | throw (New-Object System.Exception("Exception while retrieving datasource! $($_.Exception.Message)", $_.Exception)) 85 | } 86 | } 87 | } -------------------------------------------------------------------------------- /ReportingServicesTools/Functions/CatalogItems/Get-RsItemReference.ps1: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2016 Microsoft Corporation. All Rights Reserved. 2 | # Licensed under the MIT License (MIT) 3 | 4 | 5 | function Get-RsItemReference 6 | { 7 | <# 8 | .SYNOPSIS 9 | List all item references associated with a report or a dataset. 10 | 11 | .DESCRIPTION 12 | List all item references associated with a report or a dataset. 13 | For a paginated report, it lists all references to shared datasets and shared data sources. 14 | For a dataset, it lists all references to shared data sources. 15 | 16 | .PARAMETER Path 17 | Path to Item. 18 | 19 | .PARAMETER ReportServerUri 20 | Specify the Report Server URL to your SQL Server Reporting Services Instance. 21 | Use the "Connect-RsReportServer" function to set/update a default value. 22 | 23 | .PARAMETER Credential 24 | Specify the credentials to use when connecting to the Report Server. 25 | Use the "Connect-RsReportServer" function to set/update a default value. 26 | 27 | .PARAMETER Proxy 28 | Report server proxy to use. 29 | Use "New-RsWebServiceProxy" to generate a proxy object for reuse. 30 | Useful when repeatedly having to connect to multiple different Report Server. 31 | 32 | .EXAMPLE 33 | Get-RsItemReference -Path /Report1 34 | 35 | Description 36 | ----------- 37 | List all item references associated with report /Report1 38 | #> 39 | param ( 40 | [Alias('ItemPath')] 41 | [Parameter(Mandatory = $True, ValueFromPipeline = $true)] 42 | [string[]] 43 | $Path, 44 | 45 | [string] 46 | $ReportServerUri, 47 | 48 | [Alias('ReportServerCredentials')] 49 | [System.Management.Automation.PSCredential] 50 | $Credential, 51 | 52 | $Proxy 53 | ) 54 | 55 | Begin 56 | { 57 | $Proxy = New-RsWebServiceProxyHelper -BoundParameters $PSBoundParameters 58 | } 59 | 60 | Process 61 | { 62 | #region Process each path 63 | foreach ($Item in $Path) 64 | { 65 | $itemType = $Proxy.GetItemType($Item) 66 | 67 | switch ($itemType) 68 | { 69 | "Report" 70 | { 71 | return ($Proxy.GetItemReferences($Item, "DataSet") + $Proxy.GetItemReferences($Item, "DataSource")) | Add-Member -Name "ItemType" -Value $itemType -MemberType NoteProperty -PassThru 72 | } 73 | "DataSet" 74 | { 75 | return $Proxy.GetItemReferences($Item, "DataSource") | Add-Member -Name "ItemType" -Value $itemType -MemberType NoteProperty -PassThru 76 | } 77 | "Unknown" 78 | { 79 | throw "Cannot find item with path $Item" 80 | } 81 | default 82 | { 83 | throw "ItemType '$itemType' is not supported by this method." 84 | } 85 | } 86 | } 87 | #endregion Process each path 88 | } 89 | } 90 | New-Alias -Name "Get-RsItemReferences" -Value Get-RsItemReference -Scope Global 91 | -------------------------------------------------------------------------------- /ReportingServicesTools/Functions/CatalogItems/New-RsFolder.ps1: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2016 Microsoft Corporation. All Rights Reserved. 2 | # Licensed under the MIT License (MIT) 3 | 4 | function New-RsFolder 5 | { 6 | <# 7 | .SYNOPSIS 8 | This script creates a new folder in the Report Server 9 | 10 | .DESCRIPTION 11 | This script creates a new folder in the Report Server 12 | 13 | .PARAMETER RsFolder 14 | Specify the location where the folder should be created 15 | 16 | .PARAMETER FolderName 17 | Specify the name of the the new folder 18 | 19 | .PARAMETER Description 20 | Specify the description to be added to the new folder 21 | 22 | .PARAMETER Hidden 23 | Mark the item as hidden on the destination server. 24 | 25 | .PARAMETER ReportServerUri 26 | Specify the Report Server URL to your SQL Server Reporting Services Instance. 27 | Use the "Connect-RsReportServer" function to set/update a default value. 28 | 29 | .PARAMETER Credential 30 | Specify the credentials to use when connecting to the Report Server. 31 | Use the "Connect-RsReportServer" function to set/update a default value. 32 | 33 | .PARAMETER Proxy 34 | Report server proxy to use. 35 | Use "New-RsWebServiceProxy" to generate a proxy object for reuse. 36 | Useful when repeatedly having to connect to multiple different Report Server. 37 | 38 | .EXAMPLE 39 | New-RsFolder -RsFolder '/' -FolderName 'My new folder' 40 | Description 41 | ----------- 42 | This command will establish a connection to the Report Server located at http://localhost/reportserver using current user's credentials and create a new folder 'My new folder' at the root of the SSRS instance. 43 | 44 | .EXAMPLE 45 | New-RsFolder -ReportServerUri 'http://remoteServer/reportserver' -RsFolder '/existingfolder' -FolderName 'My new sub-folder' 46 | Description 47 | ----------- 48 | This command will establish a connection to the Report Server located at http://remoteServer/reportserver using current user's credentials and create a new folder 'My new sub-folder' at the folder existingfolder in the root. 49 | 50 | .EXAMPLE 51 | New-RsFolder -RsFolder '/' -FolderName 'MyDescriptiveReports' -Description 'This folder contains Descriptive Reports' 52 | Description 53 | ----------- 54 | This command will establish a connection to the Report Server located at http://localhost/reportserver using current user's credentials and create a new folder 'MyDescriptiveReports' with a Description of 'This folder contains Descriptive Reports' at the root of the SSRS instance. 55 | 56 | #> 57 | 58 | [cmdletbinding()] 59 | param 60 | ( 61 | [Parameter(Mandatory = $True)] 62 | [Alias('ItemPath','Path')] 63 | [string] 64 | $RsFolder, 65 | 66 | [Parameter(Mandatory = $True)] 67 | [Alias('Name')] 68 | [string] 69 | $FolderName, 70 | 71 | [string] 72 | $Description, 73 | 74 | [switch] 75 | $Hidden, 76 | 77 | [string] 78 | $ReportServerUri, 79 | 80 | [Alias('ReportServerCredentials')] 81 | [System.Management.Automation.PSCredential] 82 | $Credential, 83 | 84 | $Proxy 85 | ) 86 | 87 | $Proxy = New-RsWebServiceProxyHelper -BoundParameters $PSBoundParameters 88 | 89 | $namespace = $proxy.GetType().Namespace 90 | $propertyDataType = "$namespace.Property" 91 | $additionalProperties = New-Object System.Collections.Generic.List[$propertyDataType] 92 | if ($Description) 93 | { 94 | $descriptionProperty = New-Object $propertyDataType 95 | $descriptionProperty.Name = 'Description' 96 | $descriptionProperty.Value = $Description 97 | $additionalProperties.Add($descriptionProperty) 98 | } 99 | 100 | if ($Hidden) 101 | { 102 | $hiddenProperty = New-Object $propertyDataType 103 | $hiddenProperty.Name = 'Hidden' 104 | $hiddenProperty.Value = $Hidden 105 | $additionalProperties.Add($hiddenProperty) 106 | } 107 | 108 | try 109 | { 110 | Write-Verbose "Creating folder $($FolderName)..." 111 | $Proxy.CreateFolder($FolderName, $RsFolder, $additionalProperties) | Out-Null 112 | Write-Verbose "Folder $($FolderName) created successfully!" 113 | } 114 | catch 115 | { 116 | throw (New-Object System.Exception("Exception occurred while creating folder! $($_.Exception.Message)", $_.Exception)) 117 | } 118 | } -------------------------------------------------------------------------------- /ReportingServicesTools/Functions/CatalogItems/Remove-RsCatalogItem.ps1: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2016 Microsoft Corporation. All Rights Reserved. 2 | # Licensed under the MIT License (MIT) 3 | 4 | function Remove-RsCatalogItem 5 | { 6 | <# 7 | .SYNOPSIS 8 | This function removes an item from the Report Server Catalog. 9 | 10 | .DESCRIPTION 11 | This function removes an item from the Report Server Catalog. 12 | 13 | .PARAMETER RsItem 14 | Specify the path of the catalog item to remove. 15 | 16 | .PARAMETER ReportServerUri 17 | Specify the Report Server URL to your SQL Server Reporting Services Instance. 18 | Use the "Connect-RsReportServer" function to set/update a default value. 19 | 20 | .PARAMETER Credential 21 | Specify the credentials to use when connecting to the Report Server. 22 | Use the "Connect-RsReportServer" function to set/update a default value. 23 | 24 | .PARAMETER Proxy 25 | Report server proxy to use. 26 | Use "New-RsWebServiceProxy" to generate a proxy object for reuse. 27 | Useful when repeatedly having to connect to multiple different Report Server. 28 | 29 | .EXAMPLE 30 | Remove-RsCatalogItem -ReportServerUri http://localhost/ReportServer -RsItem /monthlyreports 31 | 32 | Description 33 | ----------- 34 | Removes the monthlyreports folder, located directly at the root of the SSRS instance, and all objects below it. 35 | 36 | .EXAMPLE 37 | Get-RsCatalogItems -ReportServerUri http://localhost/ReportServer_SQL2016 -RsFolder '/SQL Server Performance Dashboard' | 38 | Out-GridView -PassThru | 39 | Remove-RsCatalogItem -ReportServerUri http://localhost/ReportServer_SQL2016 40 | 41 | Description 42 | ----------- 43 | Gets a list of items from the SQL Server Performance Dashboard folder in a GridView from an SSRS instance names SQL2016 and allows the user to select items to be removed, after clicking "OK", only the items selected will be removed. 44 | #> 45 | 46 | [CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'High')] 47 | param ( 48 | [Alias('ItemPath', 'Path', 'RsFolder')] 49 | [Parameter(Mandatory = $True, ValueFromPipeline = $true)] 50 | [ System.Object[] ] 51 | $RsItem, 52 | 53 | [string] 54 | $ReportServerUri, 55 | 56 | [Alias('ReportServerCredentials')] 57 | [System.Management.Automation.PSCredential] 58 | $Credential, 59 | 60 | $Proxy 61 | ) 62 | 63 | Begin 64 | { 65 | $Proxy = New-RsWebServiceProxyHelper -BoundParameters $PSBoundParameters 66 | } 67 | 68 | Process 69 | { 70 | foreach ($item in $RsItem) 71 | { 72 | if ($PSCmdlet.ShouldProcess($item, "Delete the catalog item")) 73 | { 74 | try 75 | { 76 | Write-Verbose "Deleting catalog item $item..." 77 | if( $item -is [string] ) 78 | { 79 | $Proxy.DeleteItem($item) 80 | } 81 | else 82 | { 83 | $Proxy.DeleteItem($item.path) 84 | } 85 | Write-Verbose "Catalog item deleted successfully!" 86 | 87 | } 88 | catch 89 | { 90 | throw (New-Object System.Exception("Exception occurred while deleting catalog item '$item'! $($_.Exception.Message)", $_.Exception)) 91 | } 92 | } 93 | } 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /ReportingServicesTools/Functions/CatalogItems/Rest/Get-RsRestDataSource.ps1: -------------------------------------------------------------------------------- 1 | # Licensed under the MIT License (MIT) 2 | 3 | function Get-RsRestDataSource { 4 | <# 5 | .SYNOPSIS 6 | Fetches a data source from the report server 7 | 8 | .DESCRIPTION 9 | Fetches a data source from the report server 10 | 11 | .PARAMETER RsItem 12 | Specify the path of the data source to fetch 13 | 14 | .PARAMETER ReportPortalUri 15 | Specify the Report Portal URL to your SQL Server Reporting Services Instance. 16 | 17 | .PARAMETER RestApiVersion 18 | Specify the version of REST Endpoint to use. Valid values are: "v2.0". 19 | 20 | .PARAMETER Credential 21 | Specify the credentials to use when connecting to the Report Server. 22 | 23 | .PARAMETER WebSession 24 | Specify the session to be used when making calls to REST Endpoint. 25 | 26 | .EXAMPLE 27 | Get-RsRestDataSource -ReportPortalUri http://localhost/reports -RsItem "/MyDataSource" 28 | 29 | Fetches data source information associated to "MyDataSource" data source found in "/" folder. 30 | The returned objects properties can be found on https://app.swaggerhub.com/apis/microsoft-rs/SSRS/2.0#/DataSource 31 | 32 | .NOTES 33 | General notes 34 | #> 35 | [CmdletBinding()] 36 | param( 37 | [Parameter(Mandatory = $True)] 38 | [Alias('ItemPath','Path')] 39 | [string] 40 | $RsItem, 41 | 42 | [string] 43 | $ReportPortalUri, 44 | 45 | [Alias('ApiVersion')] 46 | [ValidateSet("v2.0")] 47 | [string] 48 | $RestApiVersion = "v2.0", 49 | 50 | [Alias('ReportServerCredentials')] 51 | [System.Management.Automation.PSCredential] 52 | $Credential, 53 | 54 | [Microsoft.PowerShell.Commands.WebRequestSession] 55 | $WebSession 56 | ) 57 | Begin 58 | { 59 | $splatInvokeWebRequest = New-RestSessionHelperSplat -BoundParameters $PSBoundParameters 60 | $ReportPortalUri = Get-RsPortalUriHelper -WebSession $splatInvokeWebRequest.WebSession 61 | $dsItemsUriFormat = $ReportPortalUri + "api/$RestApiVersion/DataSources(Path='{0}')" 62 | } 63 | Process { 64 | try { 65 | $dsItemUri = [String]::Format($dsItemsUriFormat, $RsItem) 66 | 67 | Write-Verbose "Retrieving data source contents $dsItemUri ..." 68 | $response = Invoke-WebRequest @splatInvokeWebRequest -Method 'GET' -Uri $dsItemUri 69 | $item = ConvertFrom-Json $response.Content 70 | 71 | [PSCustomObject] $item | Select-Object -ExcludeProperty '@odata.context','@odata.type' 72 | } catch { 73 | $e = $_ 74 | if ($e.ErrorDetails.Message) { 75 | $ErrorDetail = ($e.ErrorDetails.Message | ConvertFrom-Json).error 76 | } 77 | throw (New-Object System.Exception("Exception while retrieving datasource! $($ErrorDetail.message)", $e.Exception)) 78 | } 79 | } 80 | } -------------------------------------------------------------------------------- /ReportingServicesTools/Functions/CatalogItems/Rest/New-RsRestCredentialsByUserObject.ps1: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2017 Microsoft Corporation. All Rights Reserved. 2 | # Licensed under the MIT License (MIT) 3 | 4 | function New-RsRestCredentialsByUserObject 5 | { 6 | <# 7 | .SYNOPSIS 8 | This script creates a new CredentialsByUser object which can be used when updating shared/embedded data sources. 9 | 10 | .DESCRIPTION 11 | This script creates a new CredentialsByUser object which can be used when updating shared/embedded data sources. 12 | 13 | .PARAMETER PromptMessage 14 | Specify the message to display when Report Server asks user for credentials 15 | 16 | .PARAMETER WindowsCredentials 17 | Specify whether Report Server should treat user's credentials as SQL credentials or Windows credentials. 18 | 19 | .EXAMPLE 20 | New-RsRestCredentialsByUserObject 21 | 22 | Description 23 | ----------- 24 | Creates a CredentialsByUser object with all properties set to default values. 25 | 26 | .EXAMPLE 27 | New-RsRestCredentialsByUserObject -PromptMessage "Please enter your credentials" 28 | 29 | Description 30 | ----------- 31 | Creates a CredentialsByUser object with the DisplayText property set to "Please enter your credentials" 32 | 33 | .EXAMPLE 34 | New-RsRestCredentialsByUserObject -WindowsCredentials 35 | 36 | Description 37 | ----------- 38 | Creates a CredentialsByUser object with the UseAsWindowsCredentials set to true. 39 | #> 40 | [CmdletBinding()] 41 | param( 42 | [Alias('DisplayText')] 43 | [string] 44 | $PromptMessage, 45 | 46 | [Alias('UseAsWindowsCredentials')] 47 | [switch] 48 | $WindowsCredentials 49 | ) 50 | Process 51 | { 52 | return @{ 53 | "DisplayText" = $PromptMessage; 54 | "UseAsWindowsCredentials" = $WindowsCredentials -eq $true; 55 | } 56 | } 57 | } -------------------------------------------------------------------------------- /ReportingServicesTools/Functions/CatalogItems/Rest/New-RsRestCredentialsInServerObject.ps1: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2017 Microsoft Corporation. All Rights Reserved. 2 | # Licensed under the MIT License (MIT) 3 | 4 | function New-RsRestCredentialsInServerObject 5 | { 6 | <# 7 | .SYNOPSIS 8 | This script creates a new CredentialsInServer object which can be used when updating shared/embedded data sources. 9 | 10 | .DESCRIPTION 11 | This script creates a new CredentialsInServer object which can be used when updating shared/embedded data sources. 12 | 13 | .PARAMETER Username 14 | Specify the username to use when Report Server is connecting to database. 15 | 16 | .PARAMETER Password 17 | Specify the password to use when Report Server is connecting to database. 18 | 19 | .PARAMETER WindowsCredentials 20 | Specify whether Report Server should treat specified credentials as SQL credentials or Windows credentials. 21 | 22 | .PARAMETER ImpersonateUser 23 | Specify whether Report Server should try impersonating as current user when fetching data. 24 | 25 | .EXAMPLE 26 | New-RsRestCredentialsInServerObject -Credential (Get-Credential) 27 | 28 | Description 29 | ----------- 30 | Creates a CredentialsInServer object with specified username and password. 31 | 32 | .EXAMPLE 33 | New-RsRestCredentialsInServerObject -Credential (Get-Credential) -WindowsCredentials 34 | 35 | Description 36 | ----------- 37 | Creates a CredentialsInServer object with UseAsWindowsCredentials set to true and specified username and password. 38 | 39 | .EXAMPLE 40 | New-RsRestCredentialsInServerObject -Credential (Get-Credential) -ImpersonateUser 41 | 42 | Description 43 | ----------- 44 | Creates a CredentialsInServer object with ImpersonateAuthenticatedUser set to true and specified username and password. 45 | #> 46 | [CmdletBinding()] 47 | param( 48 | [Parameter(Mandatory = $True)] 49 | [System.Management.Automation.PSCredential] 50 | $Credential, 51 | 52 | [Alias('UseAsWindowsCredentials')] 53 | [switch] 54 | $WindowsCredentials, 55 | 56 | [Alias('ImpersonateAuthenticatedUser')] 57 | [switch] 58 | $ImpersonateUser 59 | ) 60 | Process 61 | { 62 | return @{ 63 | "UserName" = $Credential.Username; 64 | "Password" = $Credential.GetNetworkCredential().Password; 65 | "UseAsWindowsCredentials" = $WindowsCredentials -eq $true; 66 | "ImpersonateAuthenticatedUser" = $ImpersonateUser -eq $true; 67 | } 68 | } 69 | } -------------------------------------------------------------------------------- /ReportingServicesTools/Functions/CatalogItems/Rest/New-RsRestFolder.ps1: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2016 Microsoft Corporation. All Rights Reserved. 2 | # Licensed under the MIT License (MIT) 3 | 4 | function New-RsRestFolder 5 | { 6 | <# 7 | .SYNOPSIS 8 | This script creates a new folder in the Report Server 9 | 10 | .DESCRIPTION 11 | This script creates a new folder in the Report Server 12 | 13 | .PARAMETER RsFolder 14 | Specify the location where the folder should be created 15 | 16 | .PARAMETER FolderName 17 | Specify the name of the the new folder 18 | 19 | .PARAMETER ReportPortalUri 20 | Specify the Report Portal URL to your SQL Server Reporting Services Instance. 21 | 22 | .PARAMETER RestApiVersion 23 | Specify the version of REST Endpoint to use. Valid values are: "v2.0". 24 | 25 | .PARAMETER Credential 26 | Specify the credentials to use when connecting to the Report Server. 27 | 28 | .PARAMETER WebSession 29 | Specify the session to be used when making calls to REST Endpoint. 30 | 31 | .EXAMPLE 32 | New-RsRestFolder -FolderName MyNewFolder -RsFolder / 33 | 34 | Description 35 | ----------- 36 | Creates a new folder called "MyNewFolder" under "/" parent folder. 37 | #> 38 | 39 | [CmdletBinding()] 40 | param( 41 | [Parameter(Mandatory = $True)] 42 | [string] 43 | $RsFolder, 44 | 45 | [Parameter(Mandatory = $True)] 46 | [Alias('Name')] 47 | [string] 48 | $FolderName, 49 | 50 | [string] 51 | $ReportPortalUri, 52 | 53 | [Alias('ApiVersion')] 54 | [ValidateSet("v2.0")] 55 | [string] 56 | $RestApiVersion = "v2.0", 57 | 58 | [Alias('ReportServerCredentials')] 59 | [System.Management.Automation.PSCredential] 60 | $Credential, 61 | 62 | [Microsoft.PowerShell.Commands.WebRequestSession] 63 | $WebSession 64 | ) 65 | Begin 66 | { 67 | $WebSession = New-RsRestSessionHelper -BoundParameters $PSBoundParameters 68 | if ($null -ne $WebSession.Credentials -and $null -eq $Credential) { 69 | Write-Verbose "Using credentials from WebSession" 70 | $Credential = New-Object System.Management.Automation.PSCredential "$($WebSession.Credentials.UserName)@$($WebSession.Credentials.Domain)", $WebSession.Credentials.SecurePassword 71 | } 72 | $ReportPortalUri = Get-RsPortalUriHelper -WebSession $WebSession 73 | $foldersUri = $ReportPortalUri + "api/$RestApiVersion/Folders" 74 | } 75 | Process 76 | { 77 | try 78 | { 79 | if ($RsFolder -eq '/') 80 | { 81 | $TargetFolderPath = "/$FolderName" 82 | } 83 | else 84 | { 85 | $TargetFolderPath = "$RsFolder/$FolderName" 86 | } 87 | Write-Verbose "Creating folder $TargetFolderPath..." 88 | 89 | $payload = @{ 90 | "@odata.type" = "#Model.Folder"; 91 | "Path" = $RsFolder; 92 | "Name" = $FolderName; 93 | } 94 | $payloadJson = ConvertTo-Json $payload 95 | 96 | if ($Credential -ne $null) 97 | { 98 | $response = Invoke-WebRequest -Uri $foldersUri -Method Post -WebSession $WebSession -Body ([System.Text.Encoding]::UTF8.GetBytes($payloadJson)) -ContentType "application/json" -Credential $Credential -UseBasicParsing -Verbose:$false 99 | } 100 | else 101 | { 102 | $response = Invoke-WebRequest -Uri $foldersUri -Method Post -WebSession $WebSession -Body ([System.Text.Encoding]::UTF8.GetBytes($payloadJson)) -ContentType "application/json" -UseDefaultCredentials -UseBasicParsing -Verbose:$false 103 | } 104 | 105 | Write-Verbose "Folder $TargetFolderPath was created successfully!" 106 | return ConvertFrom-Json $response.Content 107 | } 108 | catch 109 | { 110 | throw (New-Object System.Exception("Failed to create folder '$FolderName' in '$RsFolder': $($_.Exception.Message)", $_.Exception)) 111 | } 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /ReportingServicesTools/Functions/CatalogItems/Rest/Remove-RsRestCatalogItem.ps1: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2016 Microsoft Corporation. All Rights Reserved. 2 | # Licensed under the MIT License (MIT) 3 | 4 | function Remove-RsRestCatalogItem 5 | { 6 | <# 7 | .SYNOPSIS 8 | This script deletes a catalog item from the Report Server 9 | 10 | .DESCRIPTION 11 | This script deletes a catalog item from the Report Server 12 | 13 | .PARAMETER RsItem 14 | Specify the location of the item to be deleted. 15 | 16 | .PARAMETER ReportPortalUri 17 | Specify the Report Portal URL to your SQL Server Reporting Services Instance. 18 | 19 | .PARAMETER RestApiVersion 20 | Specify the version of REST Endpoint to use. Valid values are: "v2.0". 21 | 22 | .PARAMETER Credential 23 | Specify the credentials to use when connecting to the Report Server. 24 | 25 | .PARAMETER WebSession 26 | Specify the session to be used when making calls to REST Endpoint. 27 | 28 | .EXAMPLE 29 | Remove-RsRestCatalogItem -RsItem /MyReport 30 | 31 | Description 32 | ----------- 33 | Deletes "/MyReport" catalog item from Report Server. 34 | #> 35 | 36 | [CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'High')] 37 | param( 38 | [Parameter(Mandatory = $True)] 39 | [string] 40 | $RsItem, 41 | 42 | [string] 43 | $ReportPortalUri, 44 | 45 | [Alias('ApiVersion')] 46 | [ValidateSet("v2.0")] 47 | [string] 48 | $RestApiVersion = "v2.0", 49 | 50 | [Alias('ReportServerCredentials')] 51 | [System.Management.Automation.PSCredential] 52 | $Credential, 53 | 54 | [Microsoft.PowerShell.Commands.WebRequestSession] 55 | $WebSession 56 | ) 57 | Begin 58 | { 59 | $WebSession = New-RsRestSessionHelper -BoundParameters $PSBoundParameters 60 | if ($null -ne $WebSession.Credentials -and $null -eq $Credential) { 61 | Write-Verbose "Using credentials from WebSession" 62 | $Credential = New-Object System.Management.Automation.PSCredential "$($WebSession.Credentials.UserName)@$($WebSession.Credentials.Domain)", $WebSession.Credentials.SecurePassword 63 | } 64 | $ReportPortalUri = Get-RsPortalUriHelper -WebSession $WebSession 65 | $catalogItemsUri = $ReportPortalUri + "api/$RestApiVersion/CatalogItems(Path='{0}')" 66 | } 67 | Process 68 | { 69 | if ($RsItem -eq '/') 70 | { 71 | throw "Root folder cannot be deleted!" 72 | } 73 | 74 | if ($PSCmdlet.ShouldProcess($RsItem, "Delete the item")) 75 | { 76 | try 77 | { 78 | Write-Verbose "Deleting item $RsItem..." 79 | $catalogItemsUri = [String]::Format($catalogItemsUri, $RsItem) 80 | 81 | if ($Credential -ne $null) 82 | { 83 | Invoke-WebRequest -Uri $catalogItemsUri -Method Delete -WebSession $WebSession -Credential $Credential -UseBasicParsing -Verbose:$false | Out-Null 84 | } 85 | else 86 | { 87 | Invoke-WebRequest -Uri $catalogItemsUri -Method Delete -WebSession $WebSession -UseDefaultCredentials -UseBasicParsing -Verbose:$false | Out-Null 88 | } 89 | 90 | Write-Verbose "Catalog item $RsItem was deleted successfully!" 91 | } 92 | catch 93 | { 94 | throw (New-Object System.Exception("Failed to delete catalog item '$RsItem': $($_.Exception.Message)", $_.Exception)) 95 | } 96 | } 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /ReportingServicesTools/Functions/CatalogItems/Rest/Remove-RsRestFolder.ps1: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2016 Microsoft Corporation. All Rights Reserved. 2 | # Licensed under the MIT License (MIT) 3 | 4 | function Remove-RsRestFolder 5 | { 6 | <# 7 | .SYNOPSIS 8 | This script deletes a folder from the Report Server 9 | 10 | .DESCRIPTION 11 | This script deletes a folder from the Report Server 12 | 13 | .PARAMETER RsFolder 14 | Specify the location of the folder to be deleted. 15 | 16 | .PARAMETER ReportPortalUri 17 | Specify the Report Portal URL to your SQL Server Reporting Services Instance. 18 | 19 | .PARAMETER RestApiVersion 20 | Specify the version of REST Endpoint to use. Valid values are: "v2.0". 21 | 22 | .PARAMETER Credential 23 | Specify the credentials to use when connecting to the Report Server. 24 | 25 | .PARAMETER WebSession 26 | Specify the session to be used when making calls to REST Endpoint. 27 | 28 | .EXAMPLE 29 | Remove-RsRestFolder -RsFolder /MyFolder 30 | 31 | Description 32 | ----------- 33 | Deletes "/MyFolder" folder from Report Server. 34 | #> 35 | 36 | [CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'High')] 37 | param( 38 | [Parameter(Mandatory = $True)] 39 | [string] 40 | $RsFolder, 41 | 42 | [string] 43 | $ReportPortalUri, 44 | 45 | [Alias('ApiVersion')] 46 | [ValidateSet("v2.0")] 47 | [string] 48 | $RestApiVersion = "v2.0", 49 | 50 | [Alias('ReportServerCredentials')] 51 | [System.Management.Automation.PSCredential] 52 | $Credential, 53 | 54 | [Microsoft.PowerShell.Commands.WebRequestSession] 55 | $WebSession 56 | ) 57 | Begin 58 | { 59 | $WebSession = New-RsRestSessionHelper -BoundParameters $PSBoundParameters 60 | if ($null -ne $WebSession.Credentials -and $null -eq $Credential) { 61 | Write-Verbose "Using credentials from WebSession" 62 | $Credential = New-Object System.Management.Automation.PSCredential "$($WebSession.Credentials.UserName)@$($WebSession.Credentials.Domain)", $WebSession.Credentials.SecurePassword 63 | } 64 | $ReportPortalUri = Get-RsPortalUriHelper -WebSession $WebSession 65 | $foldersUri = $ReportPortalUri + "api/$RestApiVersion/Folders(Path='{0}')" 66 | } 67 | Process 68 | { 69 | if ($RsFolder -eq '/') 70 | { 71 | throw "Root folder cannot be deleted!" 72 | } 73 | 74 | if ($PSCmdlet.ShouldProcess($RsFolder, "Delete the folder")) 75 | { 76 | try 77 | { 78 | Write-Verbose "Deleting folder $RsFolder..." 79 | $foldersUri = [String]::Format($foldersUri, $RsFolder) 80 | 81 | if ($Credential -ne $null) 82 | { 83 | Invoke-WebRequest -Uri $foldersUri -Method Delete -WebSession $WebSession -Credential $Credential -UseBasicParsing -Verbose:$false | Out-Null 84 | } 85 | else 86 | { 87 | Invoke-WebRequest -Uri $foldersUri -Method Delete -WebSession $WebSession -UseDefaultCredentials -UseBasicParsing -Verbose:$false | Out-Null 88 | } 89 | 90 | Write-Verbose "Folder $RsFolder was deleted successfully!" 91 | } 92 | catch 93 | { 94 | throw (New-Object System.Exception("Failed to delete folder '$RsFolder': $($_.Exception.Message)", $_.Exception)) 95 | } 96 | } 97 | } 98 | } -------------------------------------------------------------------------------- /ReportingServicesTools/Functions/CatalogItems/Set-RsDataSetReference.ps1: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2016 Microsoft Corporation. All Rights Reserved. 2 | # Licensed under the MIT License (MIT) 3 | 4 | 5 | function Set-RsDataSetReference 6 | { 7 | <# 8 | .SYNOPSIS 9 | Overrides the reference of a report to a shared dataset. 10 | 11 | .DESCRIPTION 12 | Overrides the reference of a report to a shared dataset. 13 | 14 | .PARAMETER Path 15 | Path of the report. 16 | 17 | .PARAMETER DataSetName 18 | Name of the dataset reference to override. 19 | 20 | .PARAMETER DataSetPath 21 | Path to the shared dataset the reference will point to. 22 | 23 | .PARAMETER ReportServerUri 24 | Specify the Report Server URL to your SQL Server Reporting Services Instance. 25 | Use the "Connect-RsReportServer" function to set/update a default value. 26 | 27 | .PARAMETER Credential 28 | Specify the credentials to use when connecting to the Report Server. 29 | Use the "Connect-RsReportServer" function to set/update a default value. 30 | 31 | .PARAMETER Proxy 32 | Report server proxy to use. 33 | Use "New-RsWebServiceProxy" to generate a proxy object for reuse. 34 | Useful when repeatedly having to connect to multiple different Report Server. 35 | 36 | .EXAMPLE 37 | Set-RsDataSetReference -ReportServerUri 'http://localhost/reportserver_sql2012' -Path /ReportWithDSReference -DataSetName Dataset1 -DataSetPath /Datasets/SampleSet 38 | 39 | Description 40 | ----------- 41 | Sets the dataset reference 'DataSet1' of report /ReportWithDSReference to point to dataset '/DataSets/SampleSet' 42 | #> 43 | [CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'Medium')] 44 | param ( 45 | [Alias('ItemPath')] 46 | [Parameter(Mandatory = $true)] 47 | [string[]] 48 | $Path, 49 | 50 | [Parameter(Mandatory = $true)] 51 | [string] 52 | $DataSetName, 53 | 54 | [Parameter(Mandatory = $true)] 55 | [string] 56 | $DataSetPath, 57 | 58 | [string] 59 | $ReportServerUri, 60 | 61 | [Alias('ReportServerCredentials')] 62 | [System.Management.Automation.PSCredential] 63 | $Credential, 64 | 65 | $Proxy 66 | ) 67 | 68 | Begin 69 | { 70 | $Proxy = New-RsWebServiceProxyHelper -BoundParameters $PSBoundParameters 71 | } 72 | 73 | Process 74 | { 75 | foreach ($item in $Path) 76 | { 77 | #region Process each path passed 78 | if ($PSCmdlet.ShouldProcess($item, "Set datasource's DataSet $DataSetName to $DataSetPath")) 79 | { 80 | Write-Verbose "Processing: $item" 81 | 82 | try 83 | { 84 | $dataSets = $Proxy.GetItemReferences($item, "DataSet") 85 | } 86 | catch 87 | { 88 | throw (New-Object System.Exception("Failed to retrieve item references from Report Server for '$item': $($_.Exception.Message)", $_.Exception)) 89 | } 90 | $dataSetReference = $dataSets | Where-Object { $_.Name -eq $DataSetName } | Select-Object -First 1 91 | 92 | if (-not $dataSetReference) 93 | { 94 | throw "$item does not contain a dataSet reference with name $DataSetName" 95 | } 96 | 97 | $proxyNamespace = $dataSetReference.GetType().Namespace 98 | $dataSetReference = New-Object "$($proxyNamespace).ItemReference" 99 | $dataSetReference.Name = $DataSetName 100 | $dataSetReference.Reference = $DataSetPath 101 | 102 | Write-Verbose "Set dataSet reference '$DataSetName' of item $item to $DataSetPath" 103 | $Proxy.SetItemReferences($item, @($dataSetReference)) 104 | } 105 | #endregion Process each path passed 106 | } 107 | } 108 | } 109 | 110 | New-Alias -Name Set-RsDataSet -Value Set-RsDataSetReference -Scope Global -------------------------------------------------------------------------------- /ReportingServicesTools/Functions/CatalogItems/Set-RsDataSourcePassword.ps1: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2016 Microsoft Corporation. All Rights Reserved. 2 | # Licensed under the MIT License (MIT) 3 | 4 | 5 | function Set-RsDataSourcePassword 6 | { 7 | <# 8 | .SYNOPSIS 9 | Overwrites the password on a Datasource. 10 | 11 | .DESCRIPTION 12 | Overwrites the password on a Datasource. 13 | 14 | .PARAMETER Path 15 | Path to DataSource. 16 | 17 | .PARAMETER Password 18 | Password to set. 19 | 20 | .PARAMETER ReportServerUri 21 | Specify the Report Server URL to your SQL Server Reporting Services Instance. 22 | Use the "Connect-RsReportServer" function to set/update a default value. 23 | 24 | .PARAMETER Credential 25 | Specify the credentials to use when connecting to the Report Server. 26 | Use the "Connect-RsReportServer" function to set/update a default value. 27 | 28 | .PARAMETER Proxy 29 | Report server proxy to use. 30 | Use "New-RsWebServiceProxy" to generate a proxy object for reuse. 31 | Useful when repeatedly having to connect to multiple different Report Server. 32 | 33 | .EXAMPLE 34 | Set-RsDataSourcePassword -ReportServerUri 'http://localhost/reportserver_sql2012' -Path /DataSource1 -Password SuperSecretPassword 35 | 36 | Description 37 | ----------- 38 | Sets the password for the datasource /DataSource1 to 'SuperSecretPassword' 39 | #> 40 | [CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'Medium')] 41 | param ( 42 | [Alias('ItemPath')] 43 | [Parameter(Mandatory = $true, ValueFromPipeline = $true)] 44 | [string[]] 45 | $Path, 46 | 47 | [Parameter(Mandatory = $true)] 48 | [string] 49 | $Password, 50 | 51 | [string] 52 | $ReportServerUri, 53 | 54 | [Alias('ReportServerCredentials')] 55 | [System.Management.Automation.PSCredential] 56 | $Credential, 57 | 58 | $Proxy 59 | ) 60 | 61 | Begin 62 | { 63 | $Proxy = New-RsWebServiceProxyHelper -BoundParameters $PSBoundParameters 64 | } 65 | 66 | Process 67 | { 68 | foreach ($item in $Path) 69 | { 70 | if ($PSCmdlet.ShouldProcess($item, "Overwrite the password")) 71 | { 72 | try 73 | { 74 | $dataSourceContent = $Proxy.GetDataSourceContents($item) 75 | } 76 | catch 77 | { 78 | throw (New-Object System.Exception("Failed to retrieve Datasource content: $($_.Exception.Message)", $_.Exception)) 79 | } 80 | $dataSourceContent.Password = $Password 81 | Write-Verbose "Setting password of datasource $item" 82 | try 83 | { 84 | $Proxy.SetDataSourceContents($item, $dataSourceContent) 85 | } 86 | catch 87 | { 88 | throw (New-Object System.Exception("Failed to update Datasource content: $($_.Exception.Message)", $_.Exception)) 89 | } 90 | } 91 | } 92 | } 93 | } 94 | 95 | -------------------------------------------------------------------------------- /ReportingServicesTools/Functions/CatalogItems/Set-RsDataSourceReference.ps1: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2016 Microsoft Corporation. All Rights Reserved. 2 | # Licensed under the MIT License (MIT) 3 | 4 | 5 | function Set-RsDataSourceReference 6 | { 7 | <# 8 | .SYNOPSIS 9 | Overrides the reference of a report or dataset to a shared data source. 10 | 11 | .DESCRIPTION 12 | Overrides the reference of a report or dataset to a shared data source. 13 | 14 | .PARAMETER Path 15 | Path of the report or dataset. 16 | 17 | .PARAMETER DataSourceName 18 | Name of the datasource reference to override. 19 | 20 | .PARAMETER DataSourcePath 21 | Path to the shared data source the reference will point to. 22 | 23 | .PARAMETER ReportServerUri 24 | Specify the Report Server URL to your SQL Server Reporting Services Instance. 25 | Use the "Connect-RsReportServer" function to set/update a default value. 26 | 27 | .PARAMETER Credential 28 | Specify the credentials to use when connecting to the Report Server. 29 | Use the "Connect-RsReportServer" function to set/update a default value. 30 | 31 | .PARAMETER Proxy 32 | Report server proxy to use. 33 | Use "New-RsWebServiceProxy" to generate a proxy object for reuse. 34 | Useful when repeatedly having to connect to multiple different Report Server. 35 | 36 | .EXAMPLE 37 | Set-RsDataSourceReference -Path /DataSet -DataSourceName DataSource1 -DataSourcePath /Datasources/SampleSource 38 | 39 | Description 40 | ----------- 41 | Sets the dataset reference 'DataSource1' of dataset '/DataSet' to point to datasource '/Datasources/SampleSource' 42 | #> 43 | [CmdletBinding()] 44 | param ( 45 | [Alias('ItemPath')] 46 | [Parameter(Mandatory = $true, ValueFromPipeline = $true)] 47 | [string[]] 48 | $Path, 49 | 50 | [Parameter(Mandatory = $true)] 51 | [string] 52 | $DataSourceName, 53 | 54 | [Parameter(Mandatory = $true)] 55 | [string] 56 | $DataSourcePath, 57 | 58 | [string] 59 | $ReportServerUri, 60 | 61 | [Alias('ReportServerCredentials')] 62 | [System.Management.Automation.PSCredential] 63 | $Credential, 64 | 65 | $Proxy 66 | ) 67 | 68 | Begin 69 | { 70 | $Proxy = New-RsWebServiceProxyHelper -BoundParameters $PSBoundParameters 71 | } 72 | 73 | Process 74 | { 75 | foreach ($item in $Path) 76 | { 77 | # For when running on Windows 6.1 with a permissive erroraction setting 78 | $dataSets = $null 79 | $dataSourceReference = $null 80 | 81 | try 82 | { 83 | $dataSets = $Proxy.GetItemReferences($item, "DataSource") 84 | } 85 | catch 86 | { 87 | throw (New-Object System.Exception("Failed to retrieve datasource item references for '$item': $($_.Exception.Message)", $_.Exception)) 88 | } 89 | $dataSourceReference = $dataSets | Where-Object { $_.Name -eq $DataSourceName } | Select-Object -First 1 90 | 91 | if (-not $dataSourceReference) 92 | { 93 | throw "$item does not contain a dataSource reference with name $DataSourceName" 94 | } 95 | 96 | $proxyNamespace = $dataSourceReference.GetType().Namespace 97 | $dataSourceReference = New-Object "$($proxyNamespace).ItemReference" 98 | $dataSourceReference.Name = $DataSourceName 99 | $dataSourceReference.Reference = $DataSourcePath 100 | 101 | Write-Verbose "Set dataSource reference '$DataSourceName' of item $item to $DataSourcePath" 102 | try 103 | { 104 | $Proxy.SetItemReferences($item, @($dataSourceReference)) 105 | } 106 | catch 107 | { 108 | throw (New-Object System.Exception("Failed to update datasource item references for '$item': $($_.Exception.Message)", $_.Exception)) 109 | } 110 | } 111 | } 112 | } 113 | 114 | New-Alias -Name "Set-RsSharedDataSource" -Value Set-RsDataSourceReference -Scope Global 115 | -------------------------------------------------------------------------------- /ReportingServicesTools/Functions/Common/Get-FileExtension.ps1: -------------------------------------------------------------------------------- 1 | function Get-FileExtension 2 | { 3 | param( 4 | [Parameter(Mandatory=$True)] 5 | [string]$TypeName 6 | ) 7 | switch ($TypeName) 8 | { 9 | 'Report' { return '.rdl' } 10 | 'DataSource' { return '.rsds' } 11 | 'DataSet' { return '.rsd' } 12 | 'MobileReport' { return '.rsmobile' } 13 | 'PowerBIReport' { return '.pbix' } 14 | 'ExcelWorkbook' { return '' } 15 | 'Resource' { return '' } 16 | 'Kpi' { return '.kpi' } 17 | 'Component' { return '' } 18 | default { throw 'Unsupported item type! We only support items which are of type Report, DataSet, DataSource, Mobile Report or Power BI Report' } 19 | } 20 | } -------------------------------------------------------------------------------- /ReportingServicesTools/Functions/Common/Get-ItemType.ps1: -------------------------------------------------------------------------------- 1 | function Get-ItemType 2 | { 3 | param 4 | ( 5 | [string]$FileExtension 6 | ) 7 | switch ($FileExtension) 8 | { 9 | '.rdl' { return 'Report' } 10 | '.rsds' { return 'DataSource' } 11 | '.rds' { return 'DataSource' } 12 | '.rsd' { return 'DataSet' } 13 | '.rsmobile' { return 'MobileReport' } 14 | '.pbix' { return 'PowerBIReport' } 15 | '.xls' { return 'ExcelWorkbook' } 16 | '.xlsx' { return 'ExcelWorkbook' } 17 | '.xlsm' { return 'ExcelWorkbook' } 18 | '.kpi' { return 'Kpi' } 19 | default { return 'Resource' } 20 | } 21 | } -------------------------------------------------------------------------------- /ReportingServicesTools/Functions/Common/MakeDeploymentFolders.ps1: -------------------------------------------------------------------------------- 1 | function MakeDeploymentFolders { 2 | param($RsFolder,$ReportPortal) 3 | $tree=$null 4 | $tree 5 | $Base='/' 6 | ($RsFolder.substring(1,$RsFolder.length-1)).split('/') | foreach{ 7 | $Folder = $_ 8 | $tree += "/"+$Folder 9 | try{ 10 | Get-RsRestItem -ReportPortalUri $ReportPortal -RsItem $tree| ft -AutoSize 11 | } 12 | catch{ 13 | Write-Warning "Folder $tree does not exist"; 14 | New-RsRestFolder -ReportPortalUri $ReportPortal -RsFolder $Base -FolderName $Folder -Verbose 15 | } 16 | $Base=$tree 17 | } 18 | } -------------------------------------------------------------------------------- /ReportingServicesTools/Functions/Common/New-RestSessionHelperSplat.ps1: -------------------------------------------------------------------------------- 1 | function New-RestSessionHelperSplat 2 | { 3 | <# 4 | .SYNOPSIS 5 | Internal helper function. Facilitates generating Rest Session objects. 6 | 7 | .DESCRIPTION 8 | Internal helper function. Facilitates generating Rest Session objects. 9 | It is an enhancement to the New-RsRestSession function - containing Credentials and UseBasicParsing. 10 | This allows simpler usage and avoids duplicated calls (Credential/UseDefaultCredentials) 11 | 12 | It accepts all bound parameters of the calling function and processes the following keys: 13 | - ReportPortalUri 14 | - RestApiVersion 15 | - Credential 16 | - WebSession 17 | These parameters are passed on to the New-RsRestSession function, unless WebSession was specified. 18 | If the bound parameters contain the WebSession parameter, the function will return that object. 19 | All other bound parameters are ignored. 20 | 21 | .PARAMETER BoundParameters 22 | The bound parameters of the calling function 23 | 24 | .EXAMPLE 25 | $RsRestWebSession = New-RestSessionHelperSplat -BoundParameters $PSBoundParameters 26 | 27 | Generates or retrieves a WebSession object and returns a hashtable to be used in further webrequest calls. 28 | 29 | .RETURNS 30 | A hastable containing all properties to be passed to a Invoke-Webrequest call using splatting. 31 | #> 32 | 33 | [CmdletBinding()] 34 | Param ( 35 | [AllowNull()] 36 | [object] 37 | $BoundParameters 38 | ) 39 | 40 | if ($BoundParameters["WebSession"]) 41 | { 42 | $session = $WebSession 43 | } else { 44 | $goodKeys = @("ReportPortalUri", "RestApiVersion", "Credential") 45 | $NewRsRestSessionParams = @{ } 46 | 47 | foreach ($key in $BoundParameters.Keys) 48 | { 49 | if ($goodKeys -contains $key) 50 | { 51 | $NewRsRestSessionParams[$key] = $BoundParameters[$key] 52 | } 53 | } 54 | 55 | $session = New-RsRestSession @NewRsRestSessionParams 56 | } 57 | if ($null -ne $session.Credentials -and $null -eq $Credential) { 58 | Write-Verbose "Using credentials from WebSession" 59 | $Credential = New-Object System.Management.Automation.PSCredential "$($session.Credentials.UserName)@$($session.Credentials.Domain)", $session.Credentials.SecurePassword 60 | } 61 | $splatInvokeWebRequest = @{ 62 | WebSession = $session 63 | UseBasicParsing = $true 64 | Verbose = $false 65 | } 66 | if ($null -ne $Credential) { 67 | $splatInvokeWebRequest.Add("Credential", $Credential) 68 | } else { 69 | $splatInvokeWebRequest.Add("UseDefaultCredentials", $true) 70 | } 71 | $splatInvokeWebRequest 72 | } -------------------------------------------------------------------------------- /ReportingServicesTools/Functions/Common/ShouldProcess.ps1: -------------------------------------------------------------------------------- 1 | function Get-ShouldProcessTargetWmi 2 | { 3 | <# 4 | .SYNOPSIS 5 | Creates the target string for a should process call of Wmi functions. 6 | 7 | .DESCRIPTION 8 | Creates the target string for a should process call of Wmi functions. 9 | 10 | .PARAMETER BoundParameters 11 | The actual PSBoundParameters object of the calling function should be passed here. 12 | 13 | .PARAMETER Target 14 | Additional piece of targeting string to be appended to the base info. 15 | 16 | .EXAMPLE 17 | Get-ShouldProcessTargetWmi -BoundParameters $PSBoundParameters 18 | 19 | Returns a string for use as target in the ShouldProcess calls of Wmi queries. 20 | The string will contain the actual values used for ComputerName, SqlVersion and SqlInstance: 21 | " () \ " 22 | 23 | e.g.: "Server01 (SqlServer2016) \ ReportServer" 24 | 25 | .EXAMPLE 26 | Get-ShouldProcessTargetWmi -BoundParameters $PSBoundParameters -Target "Foo" 27 | 28 | Returns a string for use as target in the ShouldProcess calls of Wmi queries. 29 | The string will contain the actual values used for ComputerName, SqlVersion and SqlInstance, and also have a custom value appended: 30 | " () \ : " 31 | 32 | e.g.: "Server01 (SqlServer2016) \ ReportServer : Foo" 33 | #> 34 | [CmdletBinding()] 35 | Param ( 36 | [AllowNull()] 37 | [object] 38 | $BoundParameters, 39 | 40 | [string] 41 | $Target 42 | ) 43 | 44 | if ($BoundParameters["ComputerName"]) 45 | { 46 | $Server = $BoundParameters["ComputerName"] 47 | } 48 | elseif ([Microsoft.ReportingServicesTools.ConnectionHost]::ComputerName) 49 | { 50 | $Server = [Microsoft.ReportingServicesTools.ConnectionHost]::ComputerName 51 | } 52 | else 53 | { 54 | $Server = $env:COMPUTERNAME 55 | } 56 | 57 | if ($BoundParameters["ReportServerVersion"]) 58 | { 59 | $Version = $BoundParameters["ReportServerVersion"] 60 | } 61 | else 62 | { 63 | $Version = [Microsoft.ReportingServicesTools.ConnectionHost]::Version 64 | } 65 | 66 | if ($BoundParameters["ReportServerInstance"]) 67 | { 68 | $Instance = $BoundParameters["ReportServerInstance"] 69 | } 70 | else 71 | { 72 | $Instance = ([Microsoft.ReportingServicesTools.ConnectionHost]::Instance) 73 | } 74 | 75 | if ($PSBoundParameters.ContainsKey("Target")) 76 | { 77 | return "$Server ($Version) \ $Instance : $Target" 78 | } 79 | else 80 | { 81 | return "$Server ($Version) \ $Instance" 82 | } 83 | } 84 | 85 | function Get-ShouldProcessTargetWeb 86 | { 87 | <# 88 | .SYNOPSIS 89 | Creates the target string for a should process call of Web functions. 90 | 91 | .DESCRIPTION 92 | Creates the target string for a should process call of Web functions. 93 | 94 | .PARAMETER BoundParameters 95 | The actual PSBoundParameters object of the calling function should be passed here. 96 | 97 | .PARAMETER Target 98 | Additional piece of targeting string to be appended to the base info. 99 | 100 | .EXAMPLE 101 | Get-ShouldProcessTargetweb -BoundParameters $PSBoundParameters 102 | 103 | Returns a string for use as target in the ShouldProcess calls of Web queries. 104 | The string will contain the actual value used for ReportServerUri: 105 | "" 106 | 107 | .EXAMPLE 108 | Get-ShouldProcessTargetweb -BoundParameters $PSBoundParameters -Target "Foo" 109 | 110 | Returns a string for use as target in the ShouldProcess calls of Web queries. 111 | The string will contain the actual value used for ReportServerUri and also have a custom value appended: 112 | " : " 113 | #> 114 | [CmdletBinding()] 115 | Param ( 116 | [AllowNull()] 117 | [object] 118 | $BoundParameters, 119 | 120 | [string] 121 | $Target 122 | ) 123 | 124 | if ($BoundParameters.ContainsKey("ReportServerUri")) 125 | { 126 | if ($Target) 127 | { 128 | return "$($BoundParameters["ReportServerUri"]) : $Target" 129 | } 130 | else 131 | { 132 | return $BoundParameters["ReportServerUri"] 133 | } 134 | } 135 | else 136 | { 137 | if ($Target) 138 | { 139 | return "$([Microsoft.ReportingServicesTools.ConnectionHost]::ReportServerUri) : $Target" 140 | } 141 | else 142 | { 143 | return [Microsoft.ReportingServicesTools.ConnectionHost]::ReportServerUri 144 | } 145 | } 146 | } -------------------------------------------------------------------------------- /ReportingServicesTools/Functions/Common/StringManipulation.ps1: -------------------------------------------------------------------------------- 1 | function Clear-SubString 2 | { 3 | [CmdletBinding()] 4 | param 5 | ( 6 | [Parameter(Mandatory = $True)] 7 | [string] 8 | $string, 9 | 10 | [Parameter(Mandatory = $True)] 11 | [string] 12 | $substring, 13 | 14 | [ValidateSet('front', 'back')] 15 | [string] 16 | $position 17 | ) 18 | 19 | if($position -eq "front") 20 | { 21 | $result = $string -ireplace ("^" + [regex]::Escape($substring)), "" 22 | } 23 | elseif($position -eq "back") 24 | { 25 | $result = $string -ireplace ([regex]::Escape($substring) + "$"), "" 26 | } 27 | else 28 | { 29 | $result = $string -ireplace [regex]::Escape($substring), "" 30 | } 31 | return $result 32 | } 33 | -------------------------------------------------------------------------------- /ReportingServicesTools/Functions/Utilities/Connect-RsReportServer.ps1: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2017 Friedrich Weinmann. All Rights Reserved. 2 | # Licensed under the MIT License (MIT) 3 | 4 | function Connect-RsReportServer 5 | { 6 | <# 7 | .SYNOPSIS 8 | Connects to a Reporting Server 9 | 10 | .DESCRIPTION 11 | This function can be used to specify default connection information to connect to a Reporting Server, both using WMI or WebProxy. 12 | 13 | .PARAMETER ComputerName 14 | The name of the computer to connect via WMI to. 15 | Only used for WMI access. 16 | 17 | .PARAMETER ReportServerInstance 18 | The name of the SQL Instance to connect via WMI to. 19 | Only used for WMI access. 20 | 21 | .PARAMETER ReportServerVersion 22 | The version of the SQL Server whose reporting services you connect to via WMI to. 23 | Only used for WMI access. 24 | 25 | .PARAMETER Credential 26 | The credentials used to execute all requests. Null it in order to use your current user's credentials. 27 | Used both for WMI access as well as WebApi access. 28 | 29 | .PARAMETER ReportServerUri 30 | The Uri to connect to for accessing the SOAP Endpoint. 31 | 32 | .PARAMETER ReportPortalUri 33 | The Uri to connect to for accessing the REST Endpoint. This exists in SQL Server Reporting Services 2016 and later. 34 | 35 | .PARAMETER SoapEndpointApiVersion 36 | The version of the API to use, 2010 by default. Sepcifiy '2005' or '2006' if you need 37 | to query a Sql Server Reporting Service Instance running a version prior to 38 | SQL Server 2008 R2 to access those respective APIs. 39 | 40 | .PARAMETER CustomAuthentication 41 | If the server implements a custom authentication schema such as 'Forms' instead of standard Basic/NTLM. 42 | 43 | .EXAMPLE 44 | Connect-RsReportServer -ComputerName "srv-foobar" -ReportServerInstance "Northwind" -ReportServerUri "http://srv-foobar/reportserver/" 45 | 46 | Configures WMI access to 47 | - Target the server "srv-foobar" 48 | - Target the Instance "Northwind" 49 | 50 | Configures WebApi access to 51 | - Connect to the Uri: "http://srv-foobar/reportserver/" 52 | #> 53 | 54 | [CmdletBinding()] 55 | param 56 | ( 57 | [AllowEmptyString()] 58 | [AllowNull()] 59 | [string] 60 | $ComputerName, 61 | 62 | [Alias('SqlServerInstance')] 63 | [string] 64 | $ReportServerInstance, 65 | 66 | [Alias('SqlServerVersion')] 67 | [Microsoft.ReportingServicesTools.SqlServerVersion] 68 | $ReportServerVersion, 69 | 70 | [AllowEmptyString()] 71 | [AllowNull()] 72 | [PSCredential] 73 | $Credential, 74 | 75 | [Alias('Uri')] 76 | [string] 77 | $ReportServerUri, 78 | 79 | [string] 80 | $ReportPortalUri, 81 | 82 | [switch] 83 | $RegisterProxy, 84 | 85 | [Alias('ApiVersion')] 86 | [ValidateSet('2005','2006','2010')] 87 | [string] 88 | $SoapEndpointApiVersion = '2010', 89 | 90 | [switch] 91 | $CustomAuthentication 92 | ) 93 | 94 | if ($PSBoundParameters.ContainsKey("ComputerName")) 95 | { 96 | [Microsoft.ReportingServicesTools.ConnectionHost]::ComputerName = $ComputerName 97 | } 98 | if ($PSBoundParameters.ContainsKey("ReportServerInstance")) 99 | { 100 | [Microsoft.ReportingServicesTools.ConnectionHost]::Instance = $ReportServerInstance 101 | } 102 | if ($PSBoundParameters.ContainsKey("ReportServerVersion")) 103 | { 104 | [Microsoft.ReportingServicesTools.ConnectionHost]::Version = $ReportServerVersion 105 | } 106 | if ($PSBoundParameters.ContainsKey("Credential")) 107 | { 108 | [Microsoft.ReportingServicesTools.ConnectionHost]::Credential = $Credential 109 | } 110 | 111 | if ($PSBoundParameters.ContainsKey("ReportServerUri")) 112 | { 113 | [Microsoft.ReportingServicesTools.ConnectionHost]::ReportServerUri = $ReportServerUri 114 | try 115 | { 116 | $proxy = New-RsWebServiceProxyHelper -BoundParameters $PSBoundParameters 117 | [Microsoft.ReportingServicesTools.ConnectionHost]::Proxy = $proxy 118 | } 119 | catch 120 | { 121 | throw (New-Object System.Exception("Failed to establish proxy connection to $ReportServerUri : $($_.Exception.Message)", $_.Exception)) 122 | } 123 | } 124 | 125 | if ($PSBoundParameters.ContainsKey("ReportPortalUri")) 126 | { 127 | [Microsoft.ReportingServicesTools.ConnectionHost]::ReportPortalUri = $ReportPortalUri 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /ReportingServicesTools/Functions/Utilities/New-RsCatalogItemRoleObject.ps1: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2016 Microsoft Corporation. All Rights Reserved. 2 | # Licensed under the MIT License (MIT) 3 | 4 | function New-RscatalogItemRoleObject 5 | { 6 | <# 7 | .SYNOPSIS 8 | This script creates a new Catalog Item Role Object. 9 | 10 | .DESCRIPTION 11 | This script creates a new Catalog Item Role Object. 12 | 13 | .PARAMETER Policy 14 | Specify the Catalog Item Item Policy to be used 15 | 16 | .PARAMETER Path 17 | Specify the path of the Catalog Item. 18 | 19 | .PARAMETER TypeName 20 | Specity the type of the Catalog Item 21 | 22 | .PARAMETER ParentSecurity 23 | Specifies if the Security is set to the parent of the Catalog Item. 24 | 25 | .EXAMPLE 26 | $Proxy = New-RsWebServiceProxyHelper -BoundParameters $PSBoundParameters 27 | $Policies = $Proxy.GetPolicies("/", [ref]$True) 28 | New-RsCatalogItemRoleObject -Policy $Policies -Path "/" -TypeName "Folder" 29 | 30 | Description 31 | ----------- 32 | This command will retrieve and return WMI Object associated to the default instance (MSSQLSERVER) of SQL Server 2016 Reporting Services. 33 | 34 | 35 | #> 36 | 37 | [cmdletbinding()] 38 | param 39 | ( 40 | [Parameter(Mandatory=$True)] 41 | [Object[]] $Policy, 42 | 43 | [Parameter(Mandatory=$True)] 44 | [String]$Path, 45 | 46 | [Parameter(Mandatory=$True)] 47 | [String]$TypeName, 48 | 49 | [Parameter(Mandatory=$True)] 50 | [Boolean]$ParentSecurity 51 | ) 52 | $catalogItemRoles = @() 53 | 54 | $Policy | ForEach-Object { 55 | 56 | $catalogItemRole = New-Object -TypeName PSCustomObject 57 | $catalogItemRole | Add-Member -MemberType NoteProperty -Name Identity -Value $_.GroupUserName 58 | $catalogItemRole | Add-Member -MemberType NoteProperty -Name Path -Value $Path 59 | $catalogItemRole | Add-Member -MemberType NoteProperty -Name TypeName -Value $TypeName 60 | $catalogItemRole | Add-Member -MemberType NoteProperty -Name Roles -Value $_.Roles 61 | $catalogItemRole | Add-Member -MemberType NoteProperty -Name ParentSecurity -Value $ParentSecurity 62 | 63 | $catalogItemRoles += $catalogItemRole 64 | } 65 | 66 | return $catalogItemRoles 67 | } 68 | -------------------------------------------------------------------------------- /ReportingServicesTools/Functions/Utilities/New-RsConfigurationSettingObject.ps1: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2016 Microsoft Corporation. All Rights Reserved. 2 | # Licensed under the MIT License (MIT) 3 | 4 | function New-RsConfigurationSettingObject 5 | { 6 | <# 7 | .SYNOPSIS 8 | This script creates a new WMI Object that is connected to Reporting Services WMI Provider. 9 | 10 | .DESCRIPTION 11 | This script creates a new WMI Object that is connected to Reporting Services WMI Provider. 12 | 13 | .PARAMETER ReportServerInstance 14 | Specify the name of the SQL Server Reporting Services Instance. 15 | Use the "Connect-RsReportServer" function to set/update a default value. 16 | 17 | .PARAMETER ReportServerVersion 18 | Specify the version of the SQL Server Reporting Services Instance. 19 | Use the "Connect-RsReportServer" function to set/update a default value. 20 | 21 | .PARAMETER ComputerName 22 | The Report Server to target. 23 | Use the "Connect-RsReportServer" function to set/update a default value. 24 | 25 | .PARAMETER Credential 26 | Specify the credentials to use when connecting to the Report Server. 27 | Use the "Connect-RsReportServer" function to set/update a default value. 28 | 29 | .PARAMETER MinimumReportServerVersion 30 | The minimum SQL server version required in order to establish a connection. If trying to connect to a lower version, this function will error out. 31 | This allows a function to require such minimum version, without having to complicate code by looking up defaults and considering user input. 32 | 33 | .EXAMPLE 34 | New-RsConfigurationSettingObject 35 | Description 36 | ----------- 37 | This command will retrieve and return WMI Object associated to the default instance (MSSQLSERVER) of SQL Server 2016 Reporting Services. 38 | 39 | .EXAMPLE 40 | New-RsConfigurationSettingObject -SqlServerInstance 'SQL2016' 41 | Description 42 | ----------- 43 | This command will retrieve and return WMI Object associated to the named instance (SQL2016) of SQL Server 2016 Reporting Services. 44 | 45 | .EXAMPLE 46 | New-RsConfigurationSettingObject -SqlServerVersion '11' 47 | Description 48 | ----------- 49 | This command will retrieve and return WMI Object associated to the default instance (MSSQLSERVER) of SQL Server 2012 Reporting Services. 50 | 51 | .EXAMPLE 52 | New-RsConfigurationSettingObject -SqlServerInstance 'SQL2012' -SqlServerVersion 'SQLServer2012' 53 | Description 54 | ----------- 55 | This command will retrieve and return WMI Object associated to the named instance (SQL2012) of SQL Server 2012 Reporting Services. 56 | #> 57 | 58 | [cmdletbinding()] 59 | param 60 | ( 61 | [Alias('SqlServerInstance')] 62 | [string] 63 | $ReportServerInstance = ([Microsoft.ReportingServicesTools.ConnectionHost]::Instance), 64 | 65 | [Alias('SqlServerVersion')] 66 | [Microsoft.ReportingServicesTools.SqlServerVersion] 67 | $ReportServerVersion = ([Microsoft.ReportingServicesTools.ConnectionHost]::Version), 68 | 69 | [string] 70 | $ComputerName = ([Microsoft.ReportingServicesTools.ConnectionHost]::ComputerName), 71 | 72 | [System.Management.Automation.PSCredential] 73 | $Credential = ([Microsoft.ReportingServicesTools.ConnectionHost]::Credential), 74 | 75 | [Alias('MinimumSqlServerVersion')] 76 | [Microsoft.ReportingServicesTools.SqlServerVersion] 77 | $MinimumReportServerVersion 78 | ) 79 | 80 | if (($MinimumReportServerVersion) -and ($MinimumReportServerVersion -gt $ReportServerVersion)) 81 | { 82 | throw (New-Object System.Management.Automation.PSArgumentException("Trying to connect to $ComputerName \ $ReportServerInstance, but it is only $ReportServerVersion when at least $MinimumReportServerVersion is required!")) 83 | } 84 | 85 | $getWmiObjectParameters = @{ 86 | ErrorAction = "Stop" 87 | Namespace = "root\Microsoft\SqlServer\ReportServer\RS_$ReportServerInstance\v$($ReportServerVersion.Value__)\Admin" 88 | Class = "MSReportServer_ConfigurationSetting" 89 | } 90 | 91 | if ($ComputerName) 92 | { 93 | $getWmiObjectParameters["ComputerName"] = $ComputerName 94 | } 95 | if ($Credential) 96 | { 97 | $getWmiObjectParameters["Credential"] = $Credential 98 | } 99 | 100 | $wmiObjects = Get-WmiObject @getWmiObjectParameters 101 | return $wmiObjects | Where-Object { $_.InstanceName -eq $ReportServerInstance } 102 | } 103 | -------------------------------------------------------------------------------- /ReportingServicesTools/Libraries/library.ps1: -------------------------------------------------------------------------------- 1 | $source = @" 2 | using System.Management.Automation; 3 | 4 | namespace Microsoft.ReportingServicesTools 5 | { 6 | /// 7 | /// Static class containing connection information to the reporting server. 8 | /// 9 | public static class ConnectionHost 10 | { 11 | /// 12 | /// The name of the computer to connect to using WMI 13 | /// 14 | public static string ComputerName = "localhost"; 15 | 16 | /// 17 | /// The name of the Database instance of the Report Server 18 | /// 19 | public static string Instance = "PBIRS"; 20 | 21 | /// 22 | /// The version of the Report Server 23 | /// 24 | public static SqlServerVersion Version = SqlServerVersion.PowerBIReportServer; 25 | 26 | /// 27 | /// The credentials to use when connecting to the reporting services. 28 | /// 29 | public static PSCredential Credential; 30 | 31 | /// 32 | /// The uri through which to connect to the Report Server SOAP endpoint 33 | /// 34 | public static string ReportServerUri = @"http://localhost/reportserver/"; 35 | 36 | /// 37 | /// The uri through which to connect to the Report Portal OData endpoint 38 | /// 39 | public static string ReportPortalUri = @"http://localhost/reports/"; 40 | 41 | /// 42 | /// Stores an existing WebProxy object, to avoid having to process a new object each and every time 43 | /// 44 | public static object Proxy; 45 | } 46 | 47 | /// 48 | /// The various authentication schemes an smtp server used by the reporting services may use 49 | /// 50 | public enum SmtpAuthentication 51 | { 52 | /// 53 | /// Connect to a mail server without any authentication. 54 | /// 55 | None = 0, 56 | 57 | /// 58 | /// Connect to a mail server with basic authentication. 59 | /// 60 | Basic = 1, 61 | 62 | /// 63 | /// Connect to a mail server using NTLM authentication. 64 | /// 65 | Ntlm = 2 66 | } 67 | 68 | /// 69 | /// What authentication type to use when connecting with an SQL Server 70 | /// 71 | public enum SqlServerAuthenticationType 72 | { 73 | /// 74 | /// Default Windows Authentication 75 | /// 76 | Windows = 0, 77 | 78 | /// 79 | /// The SQL Server handles identity and authorization itself 80 | /// 81 | SQL = 1, 82 | 83 | /// 84 | /// Connect to SQL Server using the same account as the one which Reporting Services Service is running as. 85 | /// 86 | ServiceAccount = 2 87 | } 88 | 89 | /// 90 | /// The various versions of SQL Server 91 | /// 92 | public enum SqlServerVersion 93 | { 94 | /// 95 | /// SQL Server 2012 96 | /// 97 | SQLServer2012 = 11, 98 | 99 | /// 100 | /// SQL Server 2014 101 | /// 102 | SQLServer2014 = 12, 103 | 104 | /// 105 | /// SQL Server 2016 106 | /// 107 | SQLServer2016 = 13, 108 | 109 | /// 110 | /// SQL Server 2017 111 | /// 112 | SQLServer2017 = 14, 113 | 114 | /// 115 | /// SQL Server 2019 116 | /// 117 | SQLServer2019 = 15, 118 | 119 | /// 120 | /// SQL Server 2022 121 | /// 122 | SQLServer2022 = 16, 123 | 124 | /// 125 | /// Power BI Report Server 126 | /// 127 | PowerBIReportServer = 15 128 | } 129 | } 130 | "@ 131 | 132 | Try { Add-Type -TypeDefinition $source -ErrorAction Stop } 133 | catch { Write-Warning "$_" } 134 | -------------------------------------------------------------------------------- /ReportingServicesTools/ReportingServicesTools.psm1: -------------------------------------------------------------------------------- 1 | . "$PSScriptRoot\Libraries\library.ps1" 2 | 3 | $scripts = Get-ChildItem "$PSScriptRoot\Functions" -Recurse -Include *.ps1 4 | foreach ($script in $scripts) { . $script } -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## Security 4 | 5 | Microsoft takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations, which include [Microsoft](https://github.com/Microsoft), [Azure](https://github.com/Azure), [DotNet](https://github.com/dotnet), [AspNet](https://github.com/aspnet), [Xamarin](https://github.com/xamarin), and [our GitHub organizations](https://opensource.microsoft.com/). 6 | 7 | If you believe you have found a security vulnerability in any Microsoft-owned repository that meets [Microsoft's definition of a security vulnerability](https://aka.ms/opensource/security/definition), please report it to us as described below. 8 | 9 | ## Reporting Security Issues 10 | 11 | **Please do not report security vulnerabilities through public GitHub issues.** 12 | 13 | Instead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://aka.ms/opensource/security/create-report). 14 | 15 | If you prefer to submit without logging in, send email to [secure@microsoft.com](mailto:secure@microsoft.com). If possible, encrypt your message with our PGP key; please download it from the [Microsoft Security Response Center PGP Key page](https://aka.ms/opensource/security/pgpkey). 16 | 17 | You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://aka.ms/opensource/security/msrc). 18 | 19 | Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue: 20 | 21 | * Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.) 22 | * Full paths of source file(s) related to the manifestation of the issue 23 | * The location of the affected source code (tag/branch/commit or direct URL) 24 | * Any special configuration required to reproduce the issue 25 | * Step-by-step instructions to reproduce the issue 26 | * Proof-of-concept or exploit code (if possible) 27 | * Impact of the issue, including how an attacker might exploit the issue 28 | 29 | This information will help us triage your report more quickly. 30 | 31 | If you are reporting for a bug bounty, more complete reports can contribute to a higher bounty award. Please visit our [Microsoft Bug Bounty Program](https://aka.ms/opensource/security/bounty) page for more details about our active programs. 32 | 33 | ## Preferred Languages 34 | 35 | We prefer all communications to be in English. 36 | 37 | ## Policy 38 | 39 | Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://aka.ms/opensource/security/cvd). 40 | 41 | 42 | -------------------------------------------------------------------------------- /Templates/ScriptTemplate.ps1: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2016 Microsoft Corporation. All Rights Reserved. 2 | # Licensed under the MIT License (MIT) 3 | 4 | 5 | function DoSomeThingTo-RSCatalogItem 6 | { 7 | <# 8 | .SYNOPSIS 9 | A brief description of the DoSomeThingTo-RSCatalogItem function. 10 | 11 | .DESCRIPTION 12 | A detailed description of the DoSomeThingTo-RSCatalogItem function. 13 | 14 | .PARAMETER ReportServerUri 15 | Specify the Report Server URL to your SQL Server Reporting Services Instance. 16 | Use the "Connect-RsReportServer" function to set/update a default value. 17 | 18 | .PARAMETER Credential 19 | Specify the password to use when connecting to your SQL Server Reporting Services Instance. 20 | Use the "Connect-RsReportServer" function to set/update a default value. 21 | 22 | .PARAMETER Proxy 23 | Report server proxy to use. 24 | Use "New-RsWebServiceProxy" to generate a proxy object for reuse. 25 | Useful when repeatedly having to connect to multiple different Report Server. 26 | 27 | .EXAMPLE 28 | PS C:\> DoSomeThingTo-RSCatalogItem 29 | 30 | Does something to an RS Catalog Item 31 | #> 32 | 33 | [CmdletBinding()] 34 | param ( 35 | [string] 36 | $ReportServerUri, 37 | 38 | [Alias('ReportServerCredentials')] 39 | [System.Management.Automation.PSCredential] 40 | $Credential, 41 | 42 | $Proxy 43 | ) 44 | 45 | Begin 46 | { 47 | $Proxy = New-RsWebServiceProxyHelper -BoundParameters $PSBoundParameters 48 | } 49 | 50 | Process 51 | { 52 | 53 | } 54 | 55 | End 56 | { 57 | 58 | } 59 | } 60 | 61 | -------------------------------------------------------------------------------- /Test.ps1: -------------------------------------------------------------------------------- 1 | Invoke-Pester -Path .\Tests\CatalogItems 2 | Invoke-Pester -Path .\Tests\Utilities 3 | -------------------------------------------------------------------------------- /Tests/Admin/Rest/Get-RsRestPublicServerSetting.Tests.ps1: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2020 Microsoft Corporation. All Rights Reserved. 2 | # Licensed under the MIT License (MIT) 3 | 4 | Describe "Get-RsRestPublicServerSetting" { 5 | Context "Get Catalog Item Policy"{ 6 | $reportPortalUri = if ($env:PesterPortalUrl -eq $null) { 'http://localhost/reports' } else { $env:PesterPortalUrl } 7 | 8 | It "Should get MaxFileSizeMb property" { 9 | $property = Get-RsRestPublicServerSetting -ReportPortalUri $reportPortalUri -Property "MaxFileSizeMb" 10 | $property | Should -Not -BeNullOrEmpty 11 | $property | Should -Be '1000' 12 | } 13 | 14 | It "Should get ShowDownloadMenu property" { 15 | $property = Get-RsRestPublicServerSetting -ReportPortalUri $reportPortalUri -Property "ShowDownloadMenu" 16 | $property | Should -Not -BeNullOrEmpty 17 | $property | Should -Be 'true' 18 | } 19 | 20 | It "Should not get BadRandomProperty property" { 21 | Get-RsRestPublicServerSetting -ReportPortalUri $reportPortalUri -Property "BadRandomProperty" | Should -BeNullOrEmpty 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Tests/Admin/RsEncryptionKey.Tests.ps1: -------------------------------------------------------------------------------- 1 | function New-TestDataSource() { 2 | $dataSource = New-Object -TypeName PSObject 3 | $dataSourceName = 'SimpleDataSource' + [System.DateTime]::Now.Ticks 4 | 5 | $dataSource | Add-Member -MemberType NoteProperty -Name Name -Value $dataSourceName 6 | $dataSource | Add-Member -MemberType NoteProperty -Name ConnectionString -Value 'Data Source=localhost;' 7 | $dataSource | Add-Member -MemberType NoteProperty -Name Extension -Value 'SQL' 8 | $dataSource | Add-Member -MemberType NoteProperty -Name CredentialRetrievalType -Value 'None' 9 | $dataSource | Add-Member -MemberType NoteProperty -Name Path -Value "/$dataSourceName" 10 | 11 | return $dataSource 12 | } 13 | 14 | function Test-AccessToEncryptedContent() { 15 | param( 16 | [Parameter(Mandatory=$True)] 17 | [PSObject]$ExpectedDataSource 18 | ) 19 | 20 | $dataSource = Get-RsDataSource -DataSourcePath $ExpectedDataSource.Path 21 | $dataSource.Extension | Should be $ExpectedDataSource.Extension 22 | $dataSource.ConnectString | Should be $ExpectedDataSource.ConnectionString 23 | $dataSource.CredentialRetrieval | Should be $ExpectedDataSource.CredentialRetrievalType 24 | } 25 | 26 | #Describe "RsEncryptionKey" { 27 | # Context "Backing up and restoring encryption key" { 28 | # $itemsToClean = New-Object System.Collections.Generic.List[string] 29 | # 30 | # It "Should allow access of encrypted content post restore" { 31 | # $dataSource = New-TestDataSource 32 | # New-RsDataSource -RsFolder '/' -Name $dataSource.Name -Extension $dataSource.Extension -ConnectionString $dataSource.ConnectionString -CredentialRetrieval $dataSource.CredentialRetrievalType 33 | # $itemsToClean.Add($dataSource.Path) 34 | # 35 | # $keyPassword = 'RS4Ever!' 36 | # $currentDir = (Resolve-Path '.').Path 37 | # $keyPath = Join-Path $currentDir -ChildPath 'key.snk' 38 | # 39 | # Backup-RsEncryptionKey -Password $keyPassword -KeyPath $keyPath -Confirm:$false -Verbose 40 | # Restore-RsEncryptionKey -Password $keyPassword -KeyPath $keyPath -Confirm:$false -Verbose 41 | # 42 | # Test-AccessToEncryptedContent -ExpectedDataSource $dataSource 43 | # } 44 | # 45 | # It "Should allow backup and restore of encryption key to relative paths" { 46 | # $dataSource = New-TestDataSource 47 | # New-RsDataSource -RsFolder '/' -Name $dataSource.Name -Extension $dataSource.Extension -ConnectionString $dataSource.ConnectionString -CredentialRetrieval $dataSource.CredentialRetrievalType 48 | # $itemsToClean.Add($dataSource.Path) 49 | # 50 | # $keyPassword = 'RS4Ever!' 51 | # $keyPath = '.\key.snk' 52 | # 53 | # Backup-RsEncryptionKey -Password $keyPassword -KeyPath $keyPath -Confirm:$false -Verbose 54 | # Restore-RsEncryptionKey -Password $keyPassword -KeyPath $keyPath -Confirm:$false -Verbose 55 | # 56 | # Test-AccessToEncryptedContent -ExpectedDataSource $dataSource 57 | # } 58 | # 59 | # BeforeEach { 60 | # $itemsToClean.Clear() 61 | # } 62 | # 63 | # AfterEach { 64 | # Remove-RsCatalogItem -Path $itemsToClean 65 | # } 66 | # } 67 | #} -------------------------------------------------------------------------------- /Tests/Admin/Set-RsDatabase.Tests.ps1: -------------------------------------------------------------------------------- 1 | function Get-DatabaseName() { 2 | $wmiObject = New-RsConfigurationSettingObject -ReportServerInstance PBIRS -ReportServerVersion PowerBIReportServer 3 | return $wmiObject.DatabaseName 4 | } 5 | 6 | function Get-CredentialType() { 7 | $wmiObject = New-RsConfigurationSettingObject -ReportServerInstance PBIRS -ReportServerVersion PowerBIReportServer 8 | switch ($wmiObject.DatabaseLogonType) { 9 | 0 { return 'Windows' } 10 | 1 { return 'SQL' } 11 | 2 { return 'ServiceAccount' } 12 | default { throw 'Invalid Credential Type!' } 13 | } 14 | } 15 | 16 | function Get-SaCredentials() { 17 | if (-not $env:SqlSaPwd) { 18 | throw 'Environment variable SqlSaPwd is not defined!' 19 | } 20 | $password = ConvertTo-SecureString -AsPlainText -Force $env:SqlSaPwd 21 | return New-Object System.Management.Automation.PSCredential('sa', $password) 22 | } 23 | 24 | Describe "Set-RsDatabase" { 25 | Context "Changing database to a new database using ServiceAccount credentials" { 26 | $databaseServerName = 'localhost' 27 | $databaseName = 'ReportServer' + [System.DateTime]::Now.Ticks 28 | $credentialType = 'ServiceAccount' 29 | Set-RsDatabase -DatabaseServerName $databaseServerName -DatabaseName $databaseName -DatabaseCredentialType $credentialType -Confirm:$false -Verbose -ReportServerInstance PBIRS -ReportServerVersion PowerBIReportServer 30 | 31 | It "Should update database and credentials" { 32 | Get-DatabaseName | Should be $databaseName 33 | Get-CredentialType | Should be $credentialType 34 | } 35 | } 36 | 37 | Context "Changing database to a new database using SQL credentials" { 38 | $databaseServerName = 'localhost' 39 | $databaseName = 'ReportServer' + [System.DateTime]::Now.Ticks 40 | $credentialType = 'SQL' 41 | $credential = Get-SaCredentials 42 | Set-RsDatabase -DatabaseServerName $databaseServerName -DatabaseName $databaseName -DatabaseCredentialType $credentialType -DatabaseCredential $credential -Confirm:$false -Verbose -ReportServerInstance PBIRS -ReportServerVersion PowerBIReportServer 43 | 44 | It "Should update database and credentials" { 45 | Get-DatabaseName | Should be $databaseName 46 | Get-CredentialType | Should be $credentialType 47 | } 48 | } 49 | 50 | Context "Changing database to an existing database using SQL credentials" { 51 | $databaseServerName = 'localhost' 52 | $databaseName = 'ReportServer' 53 | $credentialType = 'SQL' 54 | $credential = Get-SaCredentials 55 | Set-RsDatabase -DatabaseServerName $databaseServerName -DatabaseName $databaseName -DatabaseCredentialType $credentialType -DatabaseCredential $credential -IsExistingDatabase -Confirm:$false -Verbose -ReportServerInstance PBIRS -ReportServerVersion PowerBIReportServer 56 | 57 | It "Should update database and credentials" { 58 | Get-DatabaseName | Should be $databaseName 59 | Get-CredentialType | Should be $credentialType 60 | } 61 | } 62 | 63 | Context "Changing database to an existing database using ServiceAccount credentials" { 64 | $databaseServerName = 'localhost' 65 | $databaseName = 'ReportServer' 66 | $credentialType = 'ServiceAccount' 67 | Set-RsDatabase -DatabaseServerName $databaseServerName -DatabaseName $databaseName -DatabaseCredentialType $credentialType -IsExistingDatabase -Confirm:$false -Verbose -ReportServerInstance PBIRS -ReportServerVersion PowerBIReportServer 68 | 69 | It "Should update database and credentials" { 70 | Get-DatabaseName | Should be $databaseName 71 | Get-CredentialType | Should be $credentialType 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /Tests/Admin/Set-RsDatabaseCredentials.Tests.ps1: -------------------------------------------------------------------------------- 1 | function Get-CredentialType() { 2 | $wmiObject = New-RsConfigurationSettingObject -ReportServerInstance PBIRS -ReportServerVersion PowerBIReportServer 3 | switch ($wmiObject.DatabaseLogonType) { 4 | 0 { return 'Windows' } 5 | 1 { return 'SQL' } 6 | 2 { return 'ServiceAccount' } 7 | default { throw 'Invalid Credential Type!' } 8 | } 9 | } 10 | 11 | function Get-SaCredentials() { 12 | if (-not $env:SqlSaPwd) { 13 | throw 'Environment variable SqlSaPwd is not defined!' 14 | } 15 | $password = ConvertTo-SecureString -AsPlainText -Force $env:SqlSaPwd 16 | return New-Object System.Management.Automation.PSCredential('sa', $password) 17 | } 18 | 19 | Describe "Set-RsDatabaseCredentials" { 20 | Context "Changing database credential type to ServiceAccount credentials" { 21 | $credentialType = 'SQL' 22 | $credential = Get-SaCredentials 23 | Set-RsDatabaseCredentials -DatabaseCredentialType $credentialType -DatabaseCredential $credential -Confirm:$false -Verbose -ReportServerInstance PBIRS -ReportServerVersion PowerBIReportServer 24 | 25 | It "Should update credentials" { 26 | Get-CredentialType | Should be $credentialType 27 | } 28 | } 29 | 30 | Context "Changing database credential type to SQL credentials" { 31 | $credentialType = 'ServiceAccount' 32 | Set-RsDatabaseCredentials -DatabaseCredentialType $credentialType -Confirm:$false -Verbose -ReportServerInstance PBIRS -ReportServerVersion PowerBIReportServer 33 | 34 | It "Should update credentials" { 35 | Get-CredentialType | Should be $credentialType 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Tests/CatalogItems/Get-RsDataSource.Tests.ps1: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2016 Microsoft Corporation. All Rights Reserved. 2 | # Licensed under the MIT License (MIT) 3 | 4 | Function Get-ExistingDataExtension 5 | { 6 | $proxy = New-RsWebServiceProxy 7 | return $proxy.ListExtensions("Data")[0].Name 8 | } 9 | 10 | Describe "Get-RsDataSource" { 11 | 12 | Context "Get RsDataSource with ReportServerUri parameter"{ 13 | $dataSourceName = 'SutGetDataSourceReportServerUri' + [guid]::NewGuid() 14 | $extension = Get-ExistingDataExtension 15 | $credentialRetrieval = 'None' 16 | # Parameters to get the RsDataSource 17 | $dataSourcePath = '/' + $dataSourceName 18 | $reportServerUri = 'http://localhost/reportserver' 19 | New-RsDataSource -RsFolder '/' -Name $dataSourceName -Extension $extension -CredentialRetrieval $credentialRetrieval 20 | $dataSource = Get-RsDataSource -Path $dataSourcePath -ReportServerUri $reportServerUri 21 | It "Should get a RsDataSource" { 22 | $dataSource.Count | Should Be 1 23 | } 24 | # Removing folders used for testing 25 | Remove-RsCatalogItem -RsFolder $dataSourcePath -Confirm:$false 26 | } 27 | 28 | Context "Get RsDataSource with Proxy parameter"{ 29 | $dataSourceName = 'SutGetDataSourceProxy' + [guid]::NewGuid() 30 | $extension = Get-ExistingDataExtension 31 | $credentialRetrieval = 'None' 32 | # Parameters to get the RsDataSource 33 | $dataSourcePath = '/' + $dataSourceName 34 | $proxy = New-RsWebServiceProxy 35 | New-RsDataSource -RsFolder '/' -Name $dataSourceName -Extension $extension -CredentialRetrieval $credentialRetrieval 36 | $dataSource = Get-RsDataSource -Path $dataSourcePath -Proxy $proxy 37 | It "Should get a RsDataSource" { 38 | $dataSource.Count | Should Be 1 39 | } 40 | # Removing folders used for testing 41 | Remove-RsCatalogItem -RsFolder $dataSourcePath -Confirm:$false 42 | } 43 | 44 | Context "Get RsDataSource with Proxy y ReportServerUri parameters"{ 45 | $dataSourceName = 'SutGetDataSourceProxyAndReporServerUri' + [guid]::NewGuid() 46 | $extension = Get-ExistingDataExtension 47 | $credentialRetrieval = 'None' 48 | # Parameters to get the RsDataSource 49 | $dataSourcePath = '/' + $dataSourceName 50 | $reportServerUri = 'http://localhost/reportserver' 51 | $proxy = New-RsWebServiceProxy 52 | # Create a DataSource 53 | New-RsDataSource -RsFolder '/' -Name $dataSourceName -Extension $extension -CredentialRetrieval $credentialRetrieval 54 | $dataSource = Get-RsDataSource -Path $dataSourcePath -Proxy $proxy -ReportServerUri $reportServerUri 55 | It "Should get a RsDataSource" { 56 | $dataSource.Count | Should Be 1 57 | } 58 | # Removing folders used for testing 59 | Remove-RsCatalogItem -RsFolder $dataSourcePath -Confirm:$false 60 | } 61 | } -------------------------------------------------------------------------------- /Tests/CatalogItems/Get-RsDeploymentConfig.Tests.ps1: -------------------------------------------------------------------------------- 1 | 2 | Describe "Get-RsDeploymentConfig" { 3 | $RSConfig = Get-RsDeploymentConfig -RsProjectFile "$($PSScriptRoot)\TestProjects\SQLServerPerformanceDashboardReportingSolution\SQL Server Performance Dashboard\SQL Server Performance Dashboard.rptproj" -ConfigurationToUse Release 4 | 5 | Write-Verbose "$RSConfig.TargetServerURL" 6 | Write-Verbose "$RSConfig.RsProjectFolder" 7 | Write-Verbose "$RSConfig.TargetDatasetFolder" 8 | Write-Verbose "$RSConfig.TargetDatasourceFolder" 9 | Write-Verbose "$RSConfig.TargetReportPartFolder" 10 | 11 | Context "Get the Release DeploymentConfig of a ReportServer project file using ConfigurationToUse parameter"{ 12 | It "Should verify TargetServerURL matches" { 13 | $RSConfig.TargetServerURL | Should Be 'http://localhost/reportserver' 14 | } 15 | 16 | It "Should verify a config was retrieved" { 17 | @($RSConfig).Count | Should Be 1 18 | } 19 | 20 | It "Should verify the Dataset, Datasource, and ReportPart folders are NULL" { 21 | #$RSConfig = Get-RsDeploymentConfig -RsProjectFile "$($PSScriptRoot)\TestProjects\SQLServerPerformanceDashboardReportingSolution\SQL Server Performance Dashboard\SQL Server Performance Dashboard.rptproj" -ConfigurationToUse Release 22 | 23 | Write-Verbose "$RSConfig.TargetDatasetFolder" 24 | Write-Verbose "$RSConfig.TargetDatasourceFolder" 25 | Write-Verbose "$RSConfig.TargetReportPartFolder" 26 | 27 | $RSConfig.TargetDatasetFolder | Should Be '/Datasets' 28 | $RSConfig.TargetDatasourceFolder | Should Be '/Data Sources' 29 | $RSConfig.TargetReportPartFolder | Should Be 'Report Parts' 30 | } 31 | 32 | } 33 | 34 | Context "Get the DebugNull DeploymentConfig of a ReportServer project file using ConfigurationToUse parameter"{ 35 | It "Should verify TargetServerURL matches" { 36 | $RSConfig = Get-RsDeploymentConfig -RsProjectFile "$($PSScriptRoot)\TestProjects\SQLServerPerformanceDashboardReportingSolution\SQL Server Performance Dashboard\SQL Server Performance Dashboard.rptproj" -ConfigurationToUse DebugNull 37 | 38 | Write-Verbose "$RSConfig.TargetServerURL" 39 | Write-Verbose "$RSConfig.RsProjectFolder" 40 | Write-Verbose "$RSConfig.TargetDatasetFolder" 41 | Write-Verbose "$RSConfig.TargetDatasourceFolder" 42 | Write-Verbose "$RSConfig.TargetReportPartFolder" 43 | 44 | $RSConfig.TargetServerURL | Should Be 'http://localhost/reportserver' 45 | } 46 | 47 | It "Should verify a config was retrieved" { 48 | @($RSConfig).Count | Should Be 1 49 | } 50 | 51 | It "Should verify config was successfully retrieved even though Dataset, Datasource, and ReportPart folders are NULL" { 52 | $RSConfig = Get-RsDeploymentConfig -RsProjectFile "$($PSScriptRoot)\TestProjects\SQLServerPerformanceDashboardReportingSolution\SQL Server Performance Dashboard\SQL Server Performance Dashboard.rptproj" -ConfigurationToUse DebugNull 53 | 54 | $RSConfig.TargetDatasetFolder | Should BeNullOrEmpty 55 | $RSConfig.TargetDatasourceFolder | Should BeNullOrEmpty 56 | $RSConfig.TargetReportPartFolder | Should BeNullOrEmpty 57 | } 58 | 59 | } 60 | } -------------------------------------------------------------------------------- /Tests/CatalogItems/Get-RsFolderContentTests.ps1: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2016 Microsoft Corporation. All Rights Reserved. 2 | # Licensed under the MIT License (MIT) 3 | 4 | Describe "Get-RsFolderContent" { 5 | Context "Get folder with ReportServerUri parameter"{ 6 | # Create a folder 7 | $folderName = 'SutGetFolderReportServerUriParameter' + [guid]::NewGuid() 8 | New-RsFolder -Path / -FolderName $folderName 9 | $folderPath = '/' + $folderName 10 | # Declare parameter ReportServerUri 11 | $reportServerUri = 'http://localhost/reportserver' 12 | # Test if the folder can be found 13 | $folderList = Get-RsFolderContent -ReportServerUri $reportServerUri -RsFolder / 14 | $folderCount = ($folderList | Where-Object name -eq $folderName).Count 15 | It "Should found a folder" { 16 | $folderCount | Should Be 1 17 | } 18 | # Removing folders used for testing 19 | Remove-RsCatalogItem -ReportServerUri 'http://localhost/reportserver' -RsFolder $folderPath -Confirm:$false 20 | } 21 | "$($folderName)"; 22 | "$($folderList.Name)"; 23 | 24 | Context "Get folder with proxy parameter"{ 25 | # Create a folder 26 | $folderName = 'SutGetFolderProxyParameter' + [guid]::NewGuid() 27 | New-RsFolder -Path / -FolderName $folderName 28 | $folderPath = '/' + $folderName 29 | # Declare parameter proxy 30 | $proxy = New-RsWebServiceProxy 31 | # Test if the folder can be found 32 | $folderList = Get-RsFolderContent -Proxy $proxy -RsFolder / 33 | $folderCount = ($folderList | Where-Object name -eq $folderName).Count 34 | It "Should found a folder" { 35 | $folderCount | Should Be 1 36 | } 37 | # Removing folders used for testing 38 | Remove-RsCatalogItem -ReportServerUri 'http://localhost/reportserver' -RsFolder $folderPath -Confirm:$false 39 | } 40 | 41 | Context "Get folder with Proxy and ReportServerUri parameter"{ 42 | # Create a folder 43 | $folderName = 'SutGetFolderProxyAndReportServerUriParameter' + [guid]::NewGuid() 44 | New-RsFolder -Path / -FolderName $folderName 45 | $folderPath = '/' + $folderName 46 | # Declare parameter proxy and ReportServerUri 47 | $proxy = New-RsWebServiceProxy 48 | $reportServerUri = 'http://localhost/reportserver' 49 | # Test if the folder can be found 50 | $folderList = Get-RsFolderContent -Proxy $proxy -ReportServerUri $reportServerUri -RsFolder / 51 | $folderCount = ($folderList | Where-Object name -eq $folderName).Count 52 | It "Should found a folder" { 53 | $folderCount | Should Be 1 54 | } 55 | # Removing folders used for testing 56 | Remove-RsCatalogItem -ReportServerUri 'http://localhost/reportserver' -RsFolder $folderPath -Confirm:$false 57 | } 58 | 59 | Context "Get folder inside 4 folders"{ 60 | # Create the first folder in the root 61 | $sutRootFolder = 'SutGetFolderParent' + [guid]::NewGuid() 62 | New-RsFolder -Path / -FolderName $sutRootFolder 63 | # Create 5 folders, one inside the other 64 | $currentFolderDepth = 2 65 | $folderParentName = $sutRootFolder 66 | While ($currentFolderDepth -le 5) 67 | { 68 | # Create a folder in a specified path 69 | $folderParentPath += '/' + $folderParentName 70 | $folderParentName = 'SutGetFolderParent' + $currentFolderDepth 71 | New-RsFolder -Path $folderParentPath -FolderName $folderParentName 72 | $currentFolderDepth +=1 73 | 74 | } 75 | # Test if the ´SutGetFolderParent5´ folder inside the other folders can be found 76 | $fifthFolderPath = $folderParentPath + '/' + $folderParentName 77 | $rootFolderPath = '/' + $sutRootFolder 78 | $folderList = Get-RsFolderContent -RsFolder $rootFolderPath -Recurse 79 | $folderCount = ($folderList | Where-Object path -eq $fifthFolderPath).Count 80 | It "Should found 4 subfolders" { 81 | $folderCount | Should Be 1 82 | $folderList.Count | Should be 4 83 | } 84 | # Removing folders used for testing 85 | Remove-RsCatalogItem -ReportServerUri 'http://localhost/reportserver' -RsFolder $rootFolderPath -Confirm:$false 86 | } 87 | "$($folderName)"; 88 | "$($folderList.Name)"; 89 | 90 | } -------------------------------------------------------------------------------- /Tests/CatalogItems/Get-RsItemDataSource.Tests.ps1: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2017 Microsoft Corporation. All Rights Reserved. 2 | # Licensed under the MIT License (MIT) 3 | 4 | $reportServerUri = if ($env:PesterServerUrl -eq $null) { 'http://localhost/reportserver' } else { $env:PesterServerUrl } 5 | 6 | Describe "Get-RsItemDataSource" { 7 | $rsFolderPath = '' 8 | $datasourcesReportPath = '' 9 | $noDatasourcesReportPath = '' 10 | 11 | BeforeEach { 12 | # create new folder in RS 13 | $folderName = 'SUT_OutRsRestCatalogItem_' + [guid]::NewGuid() 14 | New-RsFolder -ReportServerUri $reportServerUri -RsFolder / -FolderName $folderName 15 | $rsFolderPath = '/' + $folderName 16 | 17 | $localResourcesPath = (Get-Item -Path ".\").FullName + '\Tests\CatalogItems\testResources\datasources' 18 | 19 | # upload datasourcesReport to new folder in RS 20 | Write-RsCatalogItem -ReportServerUri $reportServerUri -Path "$localResourcesPath\datasourcesReport.rdl" -RsFolder $rsFolderPath 21 | $datasourcesReportPath = "$rsFolderPath/datasourcesReport" 22 | 23 | # upload noDatasourcesReport to new folder in RS 24 | Write-RsCatalogItem -ReportServerUri $reportServerUri -Path "$localResourcesPath\noDatasourcesReport.rdl" -RsFolder $rsFolderPath 25 | $noDatasourcesReportPath = "$rsFolderPath/noDatasourcesReport" 26 | } 27 | 28 | AfterEach { 29 | Remove-RsCatalogItem -ReportServerUri $reportServerUri -RsItem $datasourcesReportPath -Confirm:$false 30 | Remove-RsCatalogItem -ReportServerUri $reportServerUri -RsItem $noDatasourcesReportPath -Confirm:$false 31 | Remove-RsCatalogItem -ReportServerUri $reportServerUri -RsItem $rsFolderPath -Confirm:$false 32 | } 33 | 34 | Context "Fetches data sources with explicit ReportServerUri parameter"{ 35 | It "Should get 0 data sources if Report doesn't have any" { 36 | $dataSource = Get-RsItemDataSource -Path $noDatasourcesReportPath -ReportServerUri $reportServerUri 37 | $dataSource.Count | Should Be 0 38 | } 39 | 40 | It "Should get correct number of data sources if report doesn't have any" { 41 | $dataSource = Get-RsItemDataSource -Path $datasourcesReportPath -ReportServerUri $reportServerUri 42 | $dataSource.Count | Should Be 2 43 | } 44 | } 45 | 46 | Context "Fetches data sources with Proxy parameter"{ 47 | $proxy = New-RsWebServiceProxy -ReportServerUri $reportserverUri 48 | 49 | It "Should get 0 data sources if Report doesn't have any" { 50 | $dataSource = Get-RsItemDataSource -Path $noDatasourcesReportPath -Proxy $proxy 51 | $dataSource.Count | Should Be 0 52 | } 53 | 54 | It "Should get correct number of data sources if report doesn't have any" { 55 | $dataSource = Get-RsItemDataSource -Path $datasourcesReportPath -Proxy $proxy 56 | $dataSource.Count | Should Be 2 57 | } 58 | } 59 | } -------------------------------------------------------------------------------- /Tests/CatalogItems/Get-RsItemReference.Tests.ps1: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2016 Microsoft Corporation. All Rights Reserved. 2 | # Licensed under the MIT License (MIT) 3 | 4 | Describe "Get-RsItemReference" { 5 | Context "Get-RsItemReference with min parameters"{ 6 | 7 | $folderName = 'SutGetRsItemReference_MinParameters' + [guid]::NewGuid() 8 | New-RsFolder -Path / -FolderName $folderName 9 | $folderPath = '/' + $folderName 10 | $localResourcesPath = (Get-Item -Path ".\").FullName + '\Tests\CatalogItems\testResources\emptyReport.rdl' 11 | Write-RsCatalogItem -Path $localResourcesPath -RsFolder $folderPath 12 | $report = (Get-RsFolderContent -RsFolder $folderPath )| Where-Object TypeName -eq 'Report' 13 | $reportReferences = Get-RsItemReference -Path $report.Path 14 | 15 | It "Should found a reference to a RsDataSet with min parameters" { 16 | $dataSetReference = $reportReferences | Where-Object ReferenceType -eq 'DataSet' 17 | $dataSetReference.Name | Should Be 'reportReferenceUnDataset' 18 | } 19 | 20 | It "Should found a reference to a RsDataSource with min parameters" { 21 | $dataSourceReference = $reportReferences | Where-Object ReferenceType -eq 'DataSource' 22 | $dataSourceReference.Name | Should Be 'reportReferenceDataSource' 23 | } 24 | Remove-RsCatalogItem -RsFolder $folderPath -Confirm:$false 25 | } 26 | 27 | Context "Get-RsItemReference with Proxy parameter"{ 28 | 29 | $folderName = 'SutGetRsItemReferenceProxynParameters' + [guid]::NewGuid() 30 | New-RsFolder -Path / -FolderName $folderName 31 | $folderPath = '/' + $folderName 32 | $localResourcesPath = (Get-Item -Path ".\").FullName + '\Tests\CatalogItems\testResources\emptyReport.rdl' 33 | Write-RsCatalogItem -Path $localResourcesPath -RsFolder $folderPath 34 | $report = (Get-RsFolderContent -RsFolder $folderPath )| Where-Object TypeName -eq 'Report' 35 | $proxy = New-RsWebServiceProxy 36 | $reportReferences = Get-RsItemReference -Path $report.Path -Proxy $proxy 37 | 38 | It "Should found a reference to a RsDataSource of a report with Proxy Parameter" { 39 | $dataSourceReference = $reportReferences | Where-Object ReferenceType -eq 'DataSource' 40 | $dataSourceReference.Name | Should Be 'reportReferenceDataSource' 41 | } 42 | Remove-RsCatalogItem -RsFolder $folderPath -Confirm:$false 43 | } 44 | 45 | Context "Get-RsItemReference with ReportServerUri Parameter"{ 46 | 47 | $folderName = 'SutGetRsItemReference_ReportServerUriParameters' + [guid]::NewGuid() 48 | New-RsFolder -Path / -FolderName $folderName 49 | $folderPath = '/' + $folderName 50 | $localResourcesPath = (Get-Item -Path ".\").FullName + '\Tests\CatalogItems\testResources\emptyReport.rdl' 51 | Write-RsCatalogItem -Path $localResourcesPath -RsFolder $folderPath 52 | $report = (Get-RsFolderContent -RsFolder $folderPath )| Where-Object TypeName -eq 'Report' 53 | $reportServerUri = 'http://localhost/reportserver' 54 | $reportReferences = Get-RsItemReference -Path $report.Path -ReportServerUri $reportServerUri 55 | 56 | It "Should found a reference to a RsDataSource of a report with ReportServerUri Parameter" { 57 | $dataSourceReference = $reportReferences | Where-Object ReferenceType -eq 'DataSource' 58 | $dataSourceReference.Name | Should Be 'reportReferenceDataSource' 59 | } 60 | Remove-RsCatalogItem -RsFolder $folderPath -Confirm:$false 61 | } 62 | 63 | Context "Get-RsItemReference with ReportServerUri and Proxy Parameter"{ 64 | 65 | $folderName = 'SutGetRsItemReference_ReportServerUriProxyParameters' + [guid]::NewGuid() 66 | New-RsFolder -Path / -FolderName $folderName 67 | $folderPath = '/' + $folderName 68 | $localResourcesPath = (Get-Item -Path ".\").FullName + '\Tests\CatalogItems\testResources\emptyReport.rdl' 69 | Write-RsCatalogItem -Path $localResourcesPath -RsFolder $folderPath 70 | $report = (Get-RsFolderContent -RsFolder $folderPath )| Where-Object TypeName -eq 'Report' 71 | $proxy = New-RsWebServiceProxy 72 | $reportServerUri = 'http://localhost/reportserver' 73 | $reportReferences = Get-RsItemReference -Path $report.Path -ReportServerUri $reportServerUri -Proxy $proxy 74 | 75 | It "Should found a reference to a RsDataSource of a report with ReportServerUri and Proxy Parameters" { 76 | $dataSourceReference = $reportReferences | Where-Object ReferenceType -eq 'DataSource' 77 | $dataSourceReference.Name | Should Be 'reportReferenceDataSource' 78 | } 79 | Remove-RsCatalogItem -RsFolder $folderPath -Confirm:$false 80 | } 81 | } -------------------------------------------------------------------------------- /Tests/CatalogItems/Import-RsSubscriptionXml.Tests.ps1: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2016 Microsoft Corporation. All Rights Reserved. 2 | # Licensed under the MIT License (MIT) 3 | 4 | $reportServerUri = if ($env:PesterServerUrl -eq $null) { 'http://localhost/reportserver' } else { $env:PesterServerUrl } 5 | 6 | Function New-InMemoryFileShareSubscription 7 | { 8 | [xml]$matchData = '2017-07-14T08:00:00.000+01:001truetruetruetruetrue' 9 | 10 | $proxy = New-RsWebServiceProxy -ReportServerUri $reportServerUri 11 | $namespace = $proxy.GetType().NameSpace 12 | 13 | $ExtensionSettingsDataType = "$namespace.ExtensionSettings" 14 | $ParameterValueOrFieldReference = "$namespace.ParameterValueOrFieldReference[]" 15 | $ParameterValueDataType = "$namespace.ParameterValue" 16 | 17 | #Set ExtensionSettings 18 | $ExtensionSettings = New-Object $ExtensionSettingsDataType 19 | $ExtensionSettings.Extension = "Report Server FileShare" 20 | 21 | #Set ParameterValues 22 | $ParameterValues = New-Object $ParameterValueOrFieldReference -ArgumentList 7 23 | 24 | $to = New-Object $ParameterValueDataType 25 | $to.Name = "PATH"; 26 | $to.Value = "\\unc\path"; 27 | $ParameterValues[0] = $to; 28 | 29 | $replyTo = New-Object $ParameterValueDataType 30 | $replyTo.Name = "FILENAME"; 31 | $replyTo.Value ="Report"; 32 | $ParameterValues[1] = $replyTo; 33 | 34 | $includeReport = New-Object $ParameterValueDataType 35 | $includeReport.Name = "FILEEXTN"; 36 | $includeReport.Value = "True"; 37 | $ParameterValues[2] = $includeReport; 38 | 39 | $renderFormat = New-Object $ParameterValueDataType 40 | $renderFormat.Name = "USERNAME"; 41 | $renderFormat.Value = "user"; 42 | $ParameterValues[3] = $renderFormat; 43 | 44 | $priority = New-Object $ParameterValueDataType 45 | $priority.Name = "RENDER_FORMAT"; 46 | $priority.Value = "PDF"; 47 | $ParameterValues[4] = $priority; 48 | 49 | $subject = New-Object $ParameterValueDataType 50 | $subject.Name = "WRITEMODE"; 51 | $subject.Value = "Overwrite"; 52 | $ParameterValues[5] = $subject; 53 | 54 | $comment = New-Object $ParameterValueDataType 55 | $comment.Name = "DEFAULTCREDENTIALS"; 56 | $comment.Value = "False"; 57 | $ParameterValues[6] = $comment; 58 | 59 | $ExtensionSettings.ParameterValues = $ParameterValues 60 | 61 | $subscription = [pscustomobject]@{ 62 | DeliverySettings = $ExtensionSettings 63 | Description = "Shared on \\unc\path" 64 | EventType = "TimedSubscription" 65 | IsDataDriven = $false 66 | MatchData = $matchData.OuterXml 67 | Values = $null 68 | } 69 | 70 | return $subscription 71 | } 72 | 73 | Describe 'Import-RsSubscriptionXml' { 74 | Context 'Import-RsSubscriptionXml' { 75 | It 'Should import a subscription' { 76 | $TestPath = 'TestDrive:\Subscription.xml' 77 | New-InMemoryFileShareSubscription | Export-RsSubscriptionXml $TestPath 78 | $Result = Import-RsSubscriptionXml $TestPath -ReportServerUri $reportServerUri 79 | 80 | $Result.Description | Should Be 'Shared on \\unc\path' 81 | } 82 | } 83 | } -------------------------------------------------------------------------------- /Tests/CatalogItems/New-RsScheduleXML.Tests.ps1: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2016 Microsoft Corporation. All Rights Reserved. 2 | # Licensed under the MIT License (MIT) 3 | 4 | #Not in use right now - need email configuration on the report server 5 | 6 | Describe 'New-RsScheduleXML' { 7 | 8 | $CurrentDate = Get-Date 9 | 10 | Context 'New-RsScheduleXML -Once' { 11 | 12 | $Schedule = New-RsScheduleXML -Once -Start $CurrentDate 13 | 14 | It 'Should return valid schedule XML' { 15 | @($Schedule).Count | Should Be 1 16 | $Schedule | Should BeOfType [String] 17 | { [xml]$Schedule } | Should Not Throw 18 | } 19 | } 20 | 21 | Context 'New-RsScheduleXML -Minute' { 22 | 23 | $Schedule = New-RsScheduleXML -Minute -Interval 90 -Start $CurrentDate 24 | 25 | It 'Should return valid schedule XML' { 26 | @($Schedule).Count | Should Be 1 27 | $Schedule | Should BeOfType [String] 28 | { [xml]$Schedule } | Should Not Throw 29 | } 30 | } 31 | 32 | Context 'New-RsScheduleXML -Daily' { 33 | 34 | $Schedule = New-RsScheduleXML -Daily -Interval 3 -Start $CurrentDate 35 | 36 | It 'Should return valid schedule XML' { 37 | @($Schedule).Count | Should Be 1 38 | $Schedule | Should BeOfType [String] 39 | { [xml]$Schedule } | Should Not Throw 40 | } 41 | } 42 | 43 | Context 'New-RsScheduleXML -Weekly' { 44 | 45 | $Schedule = New-RsScheduleXML -Weekly -Interval 2 -DaysOfWeek Monday,Tuesday,Wednesday -Start $CurrentDate 46 | 47 | It 'Should return valid schedule XML' { 48 | @($Schedule).Count | Should Be 1 49 | $Schedule | Should BeOfType [String] 50 | { [xml]$Schedule } | Should Not Throw 51 | } 52 | } 53 | 54 | Context 'New-RsScheduleXML -Monthly' { 55 | 56 | $Schedule = New-RsScheduleXML -Monthly -Months January,February,March -DaysOfMonth '1,2,3-7' -Start $CurrentDate 57 | 58 | It 'Should return valid schedule XML' { 59 | @($Schedule).Count | Should Be 1 60 | $Schedule | Should BeOfType [String] 61 | { [xml]$Schedule } | Should Not Throw 62 | } 63 | } 64 | 65 | Context 'New-RsScheduleXML -MonthlyDayOfWeek' { 66 | 67 | $Schedule = New-RsScheduleXML -MonthlyDayOfWeek -DaysOfWeek Thursday,Friday,Saturday,Sunday -Months April,May,June -WeekOfMonth LastWeek -Start $CurrentDate 68 | 69 | It 'Should return valid schedule XML' { 70 | @($Schedule).Count | Should Be 1 71 | $Schedule | Should BeOfType [String] 72 | { [xml]$Schedule } | Should Not Throw 73 | } 74 | } 75 | 76 | Context 'New-RsScheduleXML -End' { 77 | 78 | $Schedule = New-RsScheduleXML -End $CurrentDate 79 | 80 | It 'Should return valid schedule XML' { 81 | @($Schedule).Count | Should Be 1 82 | $Schedule | Should BeOfType [String] 83 | { [xml]$Schedule } | Should Not Throw 84 | } 85 | } 86 | } -------------------------------------------------------------------------------- /Tests/CatalogItems/Publish-RsProject.Test.ps1: -------------------------------------------------------------------------------- 1 | $reportPortalUri = if ($env:PesterPortalUrl -eq $null) { 'http://localhost/reports' } else { $env:PesterPortalUrl } 2 | 3 | Describe "Publish-RsProject" { 4 | Context "Deploy an entire SSRS Project by getting the Release DeploymentConfig of a ReportServer project file using ConfigurationToUse parameter"{ 5 | # Create a folder 6 | $RSConfig = Get-RsDeploymentConfig -RsProjectFile "$($PSScriptRoot)\TestProjects\SQLServerPerformanceDashboardReportingSolution\SQL Server Performance Dashboard\SQL Server Performance Dashboard.rptproj" -ConfigurationToUse Release | 7 | Add-Member -PassThru -MemberType NoteProperty -Name ReportPortal -Value $reportPortalUri 8 | 9 | # Test if the config was retrieved 10 | It "Should verify a config was retrieved" { 11 | @($RSConfig).Count | Should Be 1 12 | } 13 | 14 | # Test if the TargetServerURL in the config was found 15 | It "Should verify TargetServerURL matches" { 16 | $RSConfig.TargetServerURL | Should Be 'http://localhost/reportserver' 17 | } 18 | 19 | $RSConfig | Publish-RsProject 20 | $CatalogList = Get-RsRestFolderContent -reportPortalUri $RSConfig.ReportPortal -RsFolder '/SQL Server Performance Dashboard' -Recurse 21 | $folderCount = ($CatalogList | measure).Count 22 | It "Should find 22 reports inside the folder" { 23 | $folderCount | Should Be 22 24 | } 25 | # Removing folders used for testing 26 | Remove-RsCatalogItem -RsFolder $RSConfig.TargetReportFolder -Confirm:$false 27 | Remove-RsCatalogItem -RsFolder $RSConfig.TargetDatasetFolder -Confirm:$false 28 | Remove-RsCatalogItem -RsFolder $RSConfig.TargetDatasourceFolder -Confirm:$false 29 | 30 | } 31 | 32 | Context "Deploy an entire SSRS Project by getting the Debug DeploymentConfig of a ReportServer project file using ConfigurationToUse parameter"{ 33 | # Create a folder 34 | $RSConfig = Get-RsDeploymentConfig -RsProjectFile "$($PSScriptRoot)\TestProjects\SQLServerPerformanceDashboardReportingSolution\SQL Server Performance Dashboard\SQL Server Performance Dashboard.rptproj" -ConfigurationToUse Debug | 35 | Add-Member -PassThru -MemberType NoteProperty -Name ReportPortal -Value $reportPortalUri 36 | 37 | # Test if the config was retrieved 38 | It "Should verify a config was retrieved" { 39 | @($RSConfig).Count | Should Be 1 40 | } 41 | 42 | # Test if the TargetServerURL in the config was found 43 | It "Should verify TargetServerURL matches" { 44 | $RSConfig.TargetServerURL | Should Be 'http://localhost/reportserver' 45 | } 46 | 47 | $RSConfig | Publish-RsProject 48 | $CatalogList = Get-RsRestFolderContent -reportPortalUri $RSConfig.ReportPortal -RsFolder '/SQL Server Performance Dashboard' -Recurse 49 | $folderCount = ($CatalogList | measure).Count 50 | It "Should find 22 reports inside the folder" { 51 | $folderCount | Should Be 22 52 | } 53 | # Removing folders used for testing 54 | Remove-RsCatalogItem -RsFolder "/$($RSConfig.TargetReportFolder)" -Confirm:$false 55 | Remove-RsCatalogItem -RsFolder "/$($RSConfig.TargetDatasetFolder)" -Confirm:$false 56 | Remove-RsCatalogItem -RsFolder "/$($RSConfig.TargetDatasourceFolder)" -Confirm:$false 57 | 58 | } 59 | } -------------------------------------------------------------------------------- /Tests/CatalogItems/Rest/Get-RsRestCacheRefreshPlan.Tests.ps1: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021 Microsoft Corporation. All Rights Reserved. 2 | # Licensed under the MIT License (MIT) 3 | 4 | $reportPortalUri = if ($env:PesterPortalUrl -eq $null) { 'http://localhost/reports' } else { $env:PesterPortalUrl } 5 | $reportServerUri = if ($env:PesterServerUrl -eq $null) { 'http://localhost/reportserver' } else { $env:PesterServerUrl } 6 | 7 | function VerifyCatalogItemExists() 8 | { 9 | param( 10 | [Parameter(Mandatory = $True)] 11 | [string] 12 | $itemName, 13 | 14 | [Parameter(Mandatory = $True)] 15 | [string] 16 | $itemType, 17 | 18 | [Parameter(Mandatory = $True)] 19 | [string] 20 | $folderPath, 21 | 22 | [string] 23 | $reportPortalUri 24 | ) 25 | 26 | $item = (Get-RsRestItem -reportPortalUri $reportPortalUri -RsItem "$($folderPath)/$($itemName)" ) | Where-Object { $_.Type -eq $itemType -and $_.Name -eq $itemName } 27 | $item | Should Not BeNullOrEmpty 28 | } 29 | 30 | Describe "Get-RsRestCacheRefreshPlan" { 31 | $rsFolderPath = "" 32 | $localPath = (Get-Item -Path ".\").FullName + '\Tests\CatalogItems\testResources' 33 | 34 | BeforeEach { 35 | $folderName = 'SUT_WriteRsRestCatalogItem_' + [guid]::NewGuid() 36 | New-RsRestFolder -ReportPortalUri $reportPortalUri -RsFolder / -FolderName $folderName -Verbose 37 | $rsFolderPath = '/' + $folderName 38 | $itemPath = $localPath + '\ReportCatalog.pbix' 39 | Write-RsRestCatalogItem -ReportPortalUri $reportPortalUri -Path $itemPath -RsFolder $rsFolderPath -Verbose 40 | VerifyCatalogItemExists -itemName 'ReportCatalog' -itemType 'PowerBIReport' -folderPath $rsFolderPath -reportPortalUri $reportPortalUri 41 | 42 | $dataSources = Get-RsRestItemDataSource -RsItem "$($rsFolderPath)/ReportCatalog" -ReportPortalUri $reportPortalUri 43 | $dataSources[0].DataModelDataSource.AuthType = 'UsernamePassword' 44 | $dataSources[0].DataModelDataSource.Username = 'PBIRS' 45 | $dataSources[0].DataModelDataSource.Secret = 'password' 46 | Set-RsRestItemDataSource -RsItem "$($rsFolderPath)/ReportCatalog" -ReportPortalUri $reportPortalUri -DataSources $dataSources -RsItemType 'PowerBIReport' 47 | New-RsRestCacheRefreshPlan -RsItem "$($rsFolderPath)/ReportCatalog" -ReportPortalUri $reportPortalUri -Description 'My New Refresh Plan' -Verbose 48 | 49 | } 50 | 51 | AfterEach { 52 | Remove-RsRestCatalogItem -ReportPortalUri $reportPortalUri -RsItem $rsFolderPath -Confirm:$false 53 | } 54 | 55 | Context "ReportPortalUri parameter" { 56 | 57 | It "Should retrieve a CacheRefreshPlan for a PBIX report" { 58 | 59 | $plan = Get-RsRestCacheRefreshPlan -ReportPortalUri $reportPortalUri -RsReport "$($rsFolderPath)/ReportCatalog" 60 | $plan | Should Not BeNullOrEmpty 61 | $plan.LastStatus | Should -Be 'New Scheduled Refresh Plan' 62 | } 63 | 64 | It "Should retrieve two CacheRefreshPlans for a PBIX report" { 65 | New-RsRestCacheRefreshPlan -RsItem "$($rsFolderPath)/ReportCatalog" -ReportPortalUri $reportPortalUri -Description 'My Other Refresh Plan' -Verbose 66 | 67 | $plans = Get-RsRestCacheRefreshPlan -ReportPortalUri $reportPortalUri -RsReport "$($rsFolderPath)/ReportCatalog" 68 | $plans | Should Not BeNullOrEmpty 69 | $plans.LastStatus | Should -Be @('New Scheduled Refresh Plan', 'New Scheduled Refresh Plan') 70 | $plans | ft -AutoSize 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /Tests/CatalogItems/Rest/Get-RsRestCacheRefreshPlanHistory.Tests.ps1: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021 Microsoft Corporation. All Rights Reserved. 2 | # Licensed under the MIT License (MIT) 3 | 4 | $reportPortalUri = if ($env:PesterPortalUrl -eq $null) { 'http://localhost/reports' } else { $env:PesterPortalUrl } 5 | $reportServerUri = if ($env:PesterServerUrl -eq $null) { 'http://localhost/reportserver' } else { $env:PesterServerUrl } 6 | 7 | function VerifyCatalogItemExists() 8 | { 9 | param( 10 | [Parameter(Mandatory = $True)] 11 | [string] 12 | $itemName, 13 | 14 | [Parameter(Mandatory = $True)] 15 | [string] 16 | $itemType, 17 | 18 | [Parameter(Mandatory = $True)] 19 | [string] 20 | $folderPath, 21 | 22 | [string] 23 | $reportPortalUri 24 | ) 25 | 26 | $item = (Get-RsRestItem -reportPortalUri $reportPortalUri -RsItem "$($folderPath)/$($itemName)" ) | Where-Object { $_.Type -eq $itemType -and $_.Name -eq $itemName } 27 | $item | Should Not BeNullOrEmpty 28 | } 29 | 30 | Describe "Get-RsRestCacheRefreshPlanHistory" { 31 | $rsFolderPath = "" 32 | $localPath = (Get-Item -Path ".\").FullName + '\Tests\CatalogItems\testResources' 33 | 34 | BeforeEach { 35 | $folderName = 'SUT_GetRsRestCacheRefreshPlanHistory_' + [guid]::NewGuid() 36 | New-RsRestFolder -ReportPortalUri $reportPortalUri -RsFolder / -FolderName $folderName -Verbose 37 | $rsFolderPath = '/' + $folderName 38 | $itemPath = $localPath + '\ReportCatalog.pbix' 39 | Write-RsRestCatalogItem -ReportPortalUri $reportPortalUri -Path $itemPath -RsFolder $rsFolderPath -Verbose 40 | VerifyCatalogItemExists -itemName 'ReportCatalog' -itemType 'PowerBIReport' -folderPath $rsFolderPath -reportPortalUri $reportPortalUri 41 | 42 | $dataSources = Get-RsRestItemDataSource -RsItem "$($rsFolderPath)/ReportCatalog" -ReportPortalUri $reportPortalUri 43 | $dataSources[0].DataModelDataSource.AuthType = 'UsernamePassword' 44 | $dataSources[0].DataModelDataSource.Username = 'sa' 45 | $dataSources[0].DataModelDataSource.Secret = 'i<3ReportingServices' 46 | Set-RsRestItemDataSource -RsItem "$($rsFolderPath)/ReportCatalog" -ReportPortalUri $reportPortalUri -DataSources $dataSources -RsItemType 'PowerBIReport' 47 | New-RsRestCacheRefreshPlan -RsItem "$($rsFolderPath)/ReportCatalog" -ReportPortalUri $reportPortalUri -Description 'My New Refresh Plan' -Verbose 48 | 49 | } 50 | 51 | AfterEach { 52 | Remove-RsRestCatalogItem -ReportPortalUri $reportPortalUri -RsItem $rsFolderPath -Confirm:$false 53 | } 54 | 55 | Context "ReportPortalUri parameter" { 56 | 57 | It "Should retrieve history of all CacheRefreshPlan plan for a PBIX report" { 58 | Start-RsRestCacheRefreshPlan -ReportPortalUri $reportPortalUri -RsReport "$($rsFolderPath)/ReportCatalog" 59 | 60 | $plan = Get-RsCacheRefreshPlan -ReportPortalUri $reportPortalUri -RsReport "$($rsFolderPath)/ReportCatalog" 61 | $plan | Should Not BeNullOrEmpty 62 | $plan.LastStatus | Should Not Be 'New Scheduled Refresh Plan' 63 | 64 | $timer= get-date 65 | while ((@($someHistory).count -lt 1)) { 66 | $someHistory = Get-RsRestCacheRefreshPlanHistory -ReportPortalUri $reportPortalUri -RsReport "$($rsFolderPath)/ReportCatalog" 67 | if(((get-date)-$timer).seconds -ge 15) { 68 | break 69 | } 70 | } 71 | @($someHistory).count | Should be 1 72 | 73 | Start-RsRestCacheRefreshPlan -ReportPortalUri $reportPortalUri -RsReport "$($rsFolderPath)/ReportCatalog" 74 | $timer= get-date 75 | while ((@($moreHistory).count -lt 2)) { 76 | $moreHistory = Get-RsRestCacheRefreshPlanHistory -ReportPortalUri $reportPortalUri -RsReport "$($rsFolderPath)/ReportCatalog" 77 | if(((get-date)-$timer).seconds -ge 15) { 78 | break 79 | } 80 | } 81 | @($moreHistory).count | Should be 2 82 | } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /Tests/CatalogItems/Rest/Get-RsRestDataSource.Tests.ps1: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2023 Microsoft Corporation. All Rights Reserved. 2 | # Licensed under the MIT License (MIT) 3 | 4 | $reportPortalUri = if ($null -eq $env:PesterPortalUrl) { 'http://localhost/reports' } else { $env:PesterPortalUrl } 5 | 6 | Describe "Get-RsRestDataSource" { 7 | BeforeAll { 8 | $folderName = 'SutGetRsRestDataSource_' + [guid]::NewGuid() 9 | $dsName = 'SutWriteRsFolderContent_DataSource' 10 | $dsPath = "/$folderName/$dsName" 11 | $localPath = (Get-Item -Path ".\").FullName + '\Tests\CatalogItems\testResources' 12 | $dsLocalPath = $localPath + "\$dsName.rsds" 13 | New-RsRestFolder -ReportPortalUri $reportPortalUri -RsFolder '/' -Name $folderName 14 | Write-RsRestCatalogItem -ReportPortalUri $reportPortalUri -Path $dsLocalPath -RsFolder "/$folderName" -Overwrite 15 | } 16 | AfterAll { 17 | Remove-RsRestCatalogItem -ReportPortalUri $reportPortalUri -RsItem $dsPath -Confirm:$false 18 | Remove-RsRestFolder -ReportPortalUri $reportPortalUri -RsFolder "/$folderName" -Confirm:$false 19 | } 20 | 21 | Context "Datasource exists" { 22 | It "Should retrieve a datasource" { 23 | $ds = Get-RsRestDataSource -ReportPortalUri $reportPortalUri -RsItem $dsPath 24 | $ds.Name | Should -Be $dsName 25 | $ds.Type | Should -Be 'DataSource' 26 | $ds.ConnectionString | Should -Not -BeNullOrEmpty 27 | } 28 | } 29 | Context "Datasource does not exist" { 30 | It "Should throw" { 31 | $result = { Get-RsRestDataSource -ReportPortalUri $reportPortalUri -RsItem '/missing' } | Should -Throw -ExpectedMessage '/missing' -Because 'the invalid path was "/missing"' -PassThru 32 | $result.Exception.Message | Should -BeLike '*/missing*' 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /Tests/CatalogItems/Rest/Get-RsRestFolderContent.Tests.ps1: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2020 Microsoft Corporation. All Rights Reserved. 2 | # Licensed under the MIT License (MIT) 3 | 4 | $reportPortalUri = if ($env:PesterPortalUrl -eq $null) { 'http://localhost/reports' } else { $env:PesterPortalUrl } 5 | $reportServerUri = if ($env:PesterServerUrl -eq $null) { 'http://localhost/reportserver' } else { $env:PesterServerUrl } 6 | 7 | Describe "Get-RsRestFolderContent" { 8 | Context "Get folder with reportPortalUri parameter"{ 9 | # Create a folder 10 | $folderName = 'SutGetFolderReportPortalUriParameter' + [guid]::NewGuid() 11 | New-RsRestFolder -reportPortalUri $reportPortalUri -RsFolder / -FolderName $folderName 12 | $folderPath = '/' + $folderName 13 | # Test if the folder can be found 14 | $folderList = Get-RsRestFolderContent -reportPortalUri $reportPortalUri -RsFolder / 15 | $folderCount = ($folderList | Where-Object name -eq $folderName | measure).Count 16 | It "Should found a folder" { 17 | $folderCount | Should Be 1 18 | } 19 | Write-Host "---------------------------- 20 | " 21 | Write-Host "Showing $folderName variable for single folder test 22 | " 23 | Write-Host "$folderName" 24 | Write-Host "---------------------------- 25 | " 26 | Write-Host "Showing $folderList variable for single folder test 27 | " 28 | Write-Host "$folderList" 29 | Write-Host "---------------------------- 30 | " 31 | Write-Host "Showing $folderCount variable for single folder test 32 | " 33 | Write-Host "$folderCount" 34 | Write-Host "---------------------------- 35 | " 36 | # Removing folders used for testing 37 | Remove-RsRestCatalogItem -ReportPortalUri $reportPortalUri -RsItem $folderPath -Confirm:$false 38 | } 39 | Context "Get folder inside 4 folders"{ 40 | # Create the first folder in the root 41 | $sutRootFolder = 'SutGetFolderParent' + [guid]::NewGuid() 42 | New-RsRestFolder -reportPortalUri $reportPortalUri -RsFolder / -FolderName $sutRootFolder 43 | # Create 5 folders, one inside the other 44 | $currentFolderDepth = 2 45 | $folderParentName = $sutRootFolder 46 | While ($currentFolderDepth -le 5) 47 | { 48 | # Create a folder in a specified path 49 | $folderParentPath += '/' + $folderParentName 50 | $folderParentName = 'SutGetFolderParent' + $currentFolderDepth 51 | New-RsRestFolder -reportPortalUri $reportPortalUri -RsFolder $folderParentPath -FolderName $folderParentName 52 | $currentFolderDepth +=1 53 | 54 | } 55 | # Test if the ´SutGetFolderParent5´ folder inside the other folders can be found 56 | $fifthFolderPath = $folderParentPath + '/' + $folderParentName 57 | $rootFolderPath = '/' + $sutRootFolder 58 | $folderList = Get-RsRestFolderContent -reportPortalUri $reportPortalUri -RsFolder $rootFolderPath -Recurse 59 | $folderCount = ($folderList | Where-Object path -eq $fifthFolderPath | measure).Count 60 | It "Should found 4 subfolders" { 61 | $folderCount | Should Be 1 62 | $folderList.Count | Should be 4 63 | 64 | Write-Host "---------------------------- 65 | " 66 | Write-Host "Showing $folderName variable for 4 folders test 67 | " 68 | Write-Host "$folderName" 69 | Write-Host "---------------------------- 70 | " 71 | Write-Host "Showing $folderList variable for 4 folders test 72 | " 73 | Write-Host "$folderList" 74 | Write-Host "---------------------------- 75 | " 76 | Write-Host "Showing $folderCount variable for 4 folders test 77 | " 78 | Write-Host "$folderCount" 79 | Write-Host "---------------------------- 80 | " 81 | } 82 | # Removing folders used for testing 83 | Remove-RsRestCatalogItem -ReportPortalUri $reportPortalUri -RsItem $rootFolderPath -Confirm:$false 84 | } 85 | } -------------------------------------------------------------------------------- /Tests/CatalogItems/Rest/Get-RsRestItem.Tests.ps1: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2020 Microsoft Corporation. All Rights Reserved. 2 | # Licensed under the MIT License (MIT) 3 | 4 | $reportPortalUri = if ($env:PesterPortalUrl -eq $null) { 'http://localhost/reports' } else { $env:PesterPortalUrl } 5 | $reportServerUri = if ($env:PesterServerUrl -eq $null) { 'http://localhost/reportserver' } else { $env:PesterServerUrl } 6 | 7 | Describe "Get-RsRestItem" { 8 | Context "Get folder with reportPortalUri parameter"{ 9 | # Create a folder 10 | $folderName = 'SutGetFolderReportPortalUriParameter' + [guid]::NewGuid() 11 | New-RsRestFolder -reportPortalUri $reportPortalUri -RsFolder / -FolderName $folderName 12 | $folderPath = '/' + $folderName 13 | # Test if the folder can be found 14 | $folderList = Get-RsRestItem -reportPortalUri $reportPortalUri -RsItem $folderPath 15 | $folderCount = $folderList | Where-Object name -eq $folderName | measure 16 | It "Should found a folder" { 17 | $folderCount.Count | Should Be 1 18 | } 19 | # Removing folders used for testing 20 | Remove-RsRestCatalogItem -ReportPortalUri $reportPortalUri -RsItem $folderPath -Confirm:$false 21 | } 22 | Write-Host '---------------------------- 23 | ' 24 | Write-Host 'Showing $folderName variable for 4 folders test 25 | ' 26 | Write-Host "$($folderName)" 27 | Write-Host '---------------------------- 28 | ' 29 | Write-Host 'Showing $folderList variable for 4 folders test 30 | ' 31 | Write-Host "$($folderList)" 32 | Write-Host '---------------------------- 33 | ' 34 | Write-Host 'Showing $folderCount variable for 4 folders test 35 | ' 36 | Write-Host "$($folderCount)" 37 | Write-Host '---------------------------- 38 | ' 39 | 40 | Context "Get folder inside 4 folders"{ 41 | # Create the first folder in the root 42 | $sutRootFolder = 'SutGetFolderParent' + [guid]::NewGuid() 43 | New-RsRestFolder -reportPortalUri $reportPortalUri -RsFolder / -FolderName $sutRootFolder 44 | # Create 5 folders, one inside the other 45 | $currentFolderDepth = 2 46 | $folderParentName = $sutRootFolder 47 | While ($currentFolderDepth -le 5) 48 | { 49 | # Create a folder in a specified path 50 | $folderParentPath += '/' + $folderParentName 51 | $folderParentName = 'SutGetFolderParent' + $currentFolderDepth 52 | New-RsRestFolder -reportPortalUri $reportPortalUri -RsFolder $folderParentPath -FolderName $folderParentName 53 | $currentFolderDepth +=1 54 | 55 | } 56 | # Test if the ´SutGetFolderParent5´ folder inside the other folders can be found 57 | $fifthFolderPath = $folderParentPath + '/' + $folderParentName 58 | $rootFolderPath = '/' + $sutRootFolder 59 | $folderList = Get-RsRestItem -reportPortalUri $reportPortalUri -RsItem "$folderParentPath/$folderParentName" 60 | $folderCount = $folderList | Where-Object path -eq $fifthFolderPath | measure 61 | It "Should find 1 subfolder underneath 4 subfolders" { 62 | $folderCount.Count | Should Be 1 63 | ($folderList | measure).count | Should be 1 64 | } 65 | # Removing folders used for testing 66 | Remove-RsRestCatalogItem -ReportPortalUri $reportPortalUri -RsItem $rootFolderPath -Confirm:$false 67 | Write-Host '---------------------------- 68 | ' 69 | Write-Host 'Showing $folderName variable for 4 folders test 70 | ' 71 | Write-Host "$($folderName)" 72 | Write-Host '---------------------------- 73 | ' 74 | Write-Host 'Showing $folderList variable for 4 folders test 75 | ' 76 | Write-Host "$($folderList)" 77 | Write-Host '---------------------------- 78 | ' 79 | Write-Host 'Showing $folderCount variable for 4 folders test 80 | ' 81 | Write-Host "$($folderCount)" 82 | Write-Host '---------------------------- 83 | ' 84 | } 85 | 86 | } -------------------------------------------------------------------------------- /Tests/CatalogItems/Rest/Get-RsRestItemDataModelParameters.Tests.ps1: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2017 Microsoft Corporation. All Rights Reserved. 2 | # Licensed under the MIT License (MIT) 3 | 4 | $reportPortalUri = if ($env:PesterPortalUrl -eq $null) { 'http://localhost/reports' } else { $env:PesterPortalUrl } 5 | 6 | Describe "Get-RsRestItemDataModelParameter" { 7 | $session = $null 8 | $rsFolderPath = "" 9 | $sqlPowerBIReport = "" 10 | 11 | BeforeEach { 12 | $session = New-RsRestSession -ReportPortalUri $reportPortalUri 13 | 14 | # creating test folder 15 | $folderName = 'SUT_GetRsRestItemDataModelParameters_' + [guid]::NewGuid() 16 | New-RsRestFolder -WebSession $session -RsFolder / -FolderName $folderName 17 | $rsFolderPath = '/' + $folderName 18 | 19 | # uploading test artifacts: dataModelParametersReport.rdl and DataModelParameters.pbix 20 | $localPath = (Get-Item -Path ".\").FullName + '\Tests\CatalogItems\testResources' 21 | 22 | Write-RsRestCatalogItem -WebSession $session -Path "$localPath\DataModelParameters.pbix" -RsFolder $rsFolderPath 23 | $sqlPowerBIReport = "$rsFolderPath/DataModelParameters" 24 | } 25 | 26 | AfterEach { 27 | # deleting test folder 28 | Remove-RsRestFolder -WebSession $session -RsFolder $rsFolderPath -Confirm:$false 29 | } 30 | 31 | Context "ReportPortalUri parameter" { 32 | It "fetches parameters for power bi reports" { 33 | $dataModelParameters = Get-RsRestItemDataModelParameter -ReportPortalUri $reportPortalUri -RsItem $sqlPowerBIReport -Verbose 34 | $dataModelParameters[0].Name | Should Be "Databasename" 35 | $dataModelParameters[0].Value | Should Be "ReportServer_2019" 36 | } 37 | } 38 | 39 | Context "WebSession parameter" { 40 | $rsSession = $null 41 | 42 | BeforeEach { 43 | $rsSession = New-RsRestSession -ReportPortalUri $reportPortalUri 44 | } 45 | 46 | It "fetches data sources for power bi reports" { 47 | $dataModelParameters = Get-RsRestItemDataModelParameter -WebSession $rsSession -RsItem $sqlPowerBIReport -Verbose 48 | $dataModelParameters[0].Name | Should Be "Databasename" 49 | $dataModelParameters[0].Value | Should Be "ReportServer_2019" 50 | } 51 | } 52 | } -------------------------------------------------------------------------------- /Tests/CatalogItems/Rest/Get-RsRestItemDataSource.Tests.ps1: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2017 Microsoft Corporation. All Rights Reserved. 2 | # Licensed under the MIT License (MIT) 3 | 4 | $reportPortalUri = if ($env:PesterPortalUrl -eq $null) { 'http://localhost/reports' } else { $env:PesterPortalUrl } 5 | $reportServerUri = if ($env:PesterServerUrl -eq $null) { 'http://localhost/reportserver' } else { $env:PesterServerUrl } 6 | 7 | Describe "Get-RsRestItemDataSource" { 8 | $session = $null 9 | $rsFolderPath = "" 10 | $datasourcesReport = "" 11 | $sqlPowerBIReport = "" 12 | 13 | BeforeEach { 14 | $session = New-RsRestSession -ReportPortalUri $reportPortalUri 15 | 16 | # creating test folder 17 | $folderName = 'SUT_GetRsRestItemDataSource_' + [guid]::NewGuid() 18 | New-RsRestFolder -WebSession $session -RsFolder / -FolderName $folderName 19 | $rsFolderPath = '/' + $folderName 20 | 21 | # uploading test artifacts: datasourcesReport.rdl and SqlPowerBIReport.pbix 22 | $localPath = (Get-Item -Path ".\").FullName + '\Tests\CatalogItems\testResources' 23 | Write-RsRestCatalogItem -WebSession $session -Path "$localPath\datasources\datasourcesReport.rdl" -RsFolder $rsFolderPath 24 | $datasourcesReport = "$rsFolderPath/datasourcesReport" 25 | 26 | Write-RsRestCatalogItem -WebSession $session -Path "$localPath\SqlPowerBIReport.pbix" -RsFolder $rsFolderPath 27 | $sqlPowerBIReport = "$rsFolderPath/SqlPowerBIReport" 28 | } 29 | 30 | AfterEach { 31 | # deleting test folder 32 | Remove-RsRestFolder -WebSession $session -RsFolder $rsFolderPath -Confirm:$false 33 | } 34 | 35 | Context "ReportPortalUri parameter" { 36 | It "fetches data sources for paginated reports" { 37 | $datasources = Get-RsRestItemDataSource -ReportPortalUri $reportPortalUri -RsItem $datasourcesReport -Verbose 38 | $datasources.Count | Should Be 2 39 | $datasources[0].DataSourceType | Should Be "SQL" 40 | $datasources[0].DataSourceSubType | Should BeNullOrEmpty 41 | $datasources[0].ConnectionString | Should Be "Data Source=localhost;Initial Catalog=master" 42 | $datasources[1].DataSourceType | Should Be "SQL" 43 | $datasources[1].DataSourceSubType | Should BeNullOrEmpty 44 | $datasources[1].ConnectionString | Should Be "Data Source=localhost;Initial Catalog=model" 45 | } 46 | 47 | It "fetches data sources for power bi reports" { 48 | $datasources = Get-RsRestItemDataSource -ReportPortalUri $reportPortalUri -RsItem $sqlPowerBIReport -Verbose 49 | $datasources.GetType() | Should BeOfType System.Object 50 | $datasources.DataSourceSubType | Should Be "DataModel" 51 | $datasources.ConnectionString | Should Be "localhost;ReportServer" 52 | } 53 | } 54 | 55 | Context "WebSession parameter" { 56 | $rsSession = $null 57 | 58 | BeforeEach { 59 | $rsSession = New-RsRestSession -ReportPortalUri $reportPortalUri 60 | } 61 | 62 | It "fetches data sources for paginated reports" { 63 | $datasources = Get-RsRestItemDataSource -WebSession $rsSession -RsItem $datasourcesReport -Verbose 64 | $datasources.Count | Should Be 2 65 | $datasources[0].DataSourceType | Should Be "SQL" 66 | $datasources[0].DataSourceSubType | Should BeNullOrEmpty 67 | $datasources[0].ConnectionString | Should Be "Data Source=localhost;Initial Catalog=master" 68 | $datasources[1].DataSourceType | Should Be "SQL" 69 | $datasources[1].DataSourceSubType | Should BeNullOrEmpty 70 | $datasources[1].ConnectionString | Should Be "Data Source=localhost;Initial Catalog=model" 71 | } 72 | 73 | It "fetches data sources for power bi reports" { 74 | $datasources = Get-RsRestItemDataSource -WebSession $rsSession -RsItem $sqlPowerBIReport -Verbose 75 | $datasources.GetType() | Should BeOfType System.Object 76 | $datasources.DataSourceSubType | Should Be "DataModel" 77 | $datasources.ConnectionString | Should Be "localhost;ReportServer" 78 | } 79 | } 80 | } -------------------------------------------------------------------------------- /Tests/CatalogItems/Rest/New-RsRestCacheRefreshPlan.Tests.ps1: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021 Microsoft Corporation. All Rights Reserved. 2 | # Licensed under the MIT License (MIT) 3 | 4 | $reportPortalUri = if ($env:PesterPortalUrl -eq $null) { 'http://localhost/reports' } else { $env:PesterPortalUrl } 5 | $reportServerUri = if ($env:PesterServerUrl -eq $null) { 'http://localhost/reportserver' } else { $env:PesterServerUrl } 6 | 7 | function VerifyCatalogItemExists() 8 | { 9 | param( 10 | [Parameter(Mandatory = $True)] 11 | [string] 12 | $itemName, 13 | 14 | [Parameter(Mandatory = $True)] 15 | [string] 16 | $itemType, 17 | 18 | [Parameter(Mandatory = $True)] 19 | [string] 20 | $folderPath, 21 | 22 | [string] 23 | $reportPortalUri 24 | ) 25 | 26 | $item = (Get-RsRestItem -reportPortalUri $reportPortalUri -RsItem "$($folderPath)/$($itemName)" ) | Where-Object { $_.Type -eq $itemType -and $_.Name -eq $itemName } 27 | $item | Should Not BeNullOrEmpty 28 | } 29 | 30 | Describe "New-RsRestCacheRefreshPlan" { 31 | $rsFolderPath = "" 32 | $localPath = (Get-Item -Path ".\").FullName + '\Tests\CatalogItems\testResources' 33 | 34 | BeforeEach { 35 | $folderName = 'SUT_WriteRsRestCatalogItem_' + [guid]::NewGuid() 36 | New-RsRestFolder -ReportPortalUri $reportPortalUri -RsFolder / -FolderName $folderName -Verbose 37 | $rsFolderPath = '/' + $folderName 38 | $itemPath = $localPath + '\ReportCatalog.pbix' 39 | Write-RsRestCatalogItem -ReportPortalUri $reportPortalUri -Path $itemPath -RsFolder $rsFolderPath -Verbose 40 | VerifyCatalogItemExists -itemName 'ReportCatalog' -itemType 'PowerBIReport' -folderPath $rsFolderPath -reportPortalUri $reportPortalUri 41 | 42 | $dataSources = Get-RsRestItemDataSource -RsItem "$($rsFolderPath)/ReportCatalog" -ReportPortalUri $reportPortalUri 43 | $dataSources[0].DataModelDataSource.AuthType = 'UsernamePassword' 44 | $dataSources[0].DataModelDataSource.Username = 'PBIRS' 45 | $dataSources[0].DataModelDataSource.Secret = 'password' 46 | Set-RsRestItemDataSource -RsItem "$($rsFolderPath)/ReportCatalog" -ReportPortalUri $reportPortalUri -DataSources $dataSources -RsItemType 'PowerBIReport' 47 | 48 | } 49 | 50 | AfterEach { 51 | Remove-RsRestCatalogItem -ReportPortalUri $reportPortalUri -RsItem $rsFolderPath -Confirm:$false 52 | } 53 | 54 | Context "ReportPortalUri parameter" { 55 | 56 | It "Should add a CacheRefreshPlan plan for a PBIX report" { 57 | New-RsRestCacheRefreshPlan -RsItem "$($rsFolderPath)/ReportCatalog" -ReportPortalUri $reportPortalUri -Description 'My New Refresh Plan' -Verbose 58 | 59 | $plan = Get-RsCacheRefreshPlan -ReportPortalUri $reportPortalUri -RsReport "$($rsFolderPath)/ReportCatalog" 60 | $plan | Should Not BeNullOrEmpty 61 | } 62 | 63 | It "Should add a CacheRefreshPlan plan for a PBIX report" { 64 | New-RsRestCacheRefreshPlan -RsItem "$($rsFolderPath)/ReportCatalog" -ReportPortalUri $reportPortalUri -StartDateTime "2021-01-07T06:00:00-00:00" -Recurrence @{ 65 | "DailyRecurrence" = @{ 66 | "DaysInterval" = "1"; 67 | } 68 | } -Verbose 69 | 70 | $plan = Get-RsCacheRefreshPlan -ReportPortalUri $reportPortalUri -RsReport "$($rsFolderPath)/ReportCatalog" 71 | $plan[0].Schedule.Definition.StartDateTime | Should Be @('2021-01-07T06:00:00Z') 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /Tests/CatalogItems/Rest/New-RsRestFolder.Tests.ps1: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2016 Microsoft Corporation. All Rights Reserved. 2 | # Licensed under the MIT License (MIT) 3 | 4 | $reportPortalUri = if ($env:PesterPortalUrl -eq $null) { 'http://localhost/reports' } else { $env:PesterPortalUrl } 5 | $reportServerUri = if ($env:PesterServerUrl -eq $null) { 'http://localhost/reportserver' } else { $env:PesterServerUrl } 6 | 7 | function VerifyCatalogItemExists() 8 | { 9 | param( 10 | [Parameter(Mandatory = $True)] 11 | [string] 12 | $itemName, 13 | 14 | [Parameter(Mandatory = $True)] 15 | [string] 16 | $itemType, 17 | 18 | [Parameter(Mandatory = $True)] 19 | [string] 20 | $folderPath, 21 | 22 | [string] 23 | $reportServerUri 24 | ) 25 | 26 | $item = (Get-RsFolderContent -ReportServerUri $reportServerUri -RsFolder $folderPath) | Where { $_.TypeName -eq $itemType -and $_.Name -eq $itemName } 27 | $item | Should Not BeNullOrEmpty 28 | } 29 | 30 | Describe "New-RsRestFolder" { 31 | Context "ReportPortalUri parameter" { 32 | It "Should create a folder" { 33 | $folderName = "SUT_NewRsRestFolder_" + [Guid]::NewGuid() 34 | New-RsRestFolder -ReportPortalUri $reportPortalUri -FolderName $folderName -RsFolder / -Verbose 35 | VerifyCatalogItemExists -itemType "Folder" -itemName $folderName -folderPath "/" -reportServerUri $reportServerUri 36 | Remove-RsCatalogItem -ReportServerUri $reportServerUri -RsFolder "/$folderName" -Confirm:$false 37 | } 38 | } 39 | 40 | Context "WebSession parameter" { 41 | $webSession = New-RsRestSession -ReportPortalUri $reportPortalUri 42 | 43 | It "Should create a folder" { 44 | $folderName = "SUT_NewRsRestFolder_" + [Guid]::NewGuid() 45 | New-RsRestFolder -WebSession $webSession -FolderName $folderName -RsFolder / -Verbose 46 | VerifyCatalogItemExists -itemType "Folder" -itemName $folderName -folderPath "/" -reportServerUri $reportServerUri 47 | Remove-RsCatalogItem -ReportServerUri $reportServerUri -RsFolder "/$folderName" -Confirm:$false 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /Tests/CatalogItems/Rest/Remove-RsRestCacheRefreshPlan.Tests.ps1: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021 Microsoft Corporation. All Rights Reserved. 2 | # Licensed under the MIT License (MIT) 3 | 4 | $reportPortalUri = if ($env:PesterPortalUrl -eq $null) { 'http://localhost/reports' } else { $env:PesterPortalUrl } 5 | $reportServerUri = if ($env:PesterServerUrl -eq $null) { 'http://localhost/reportserver' } else { $env:PesterServerUrl } 6 | 7 | function VerifyCatalogItemExists() 8 | { 9 | param( 10 | [Parameter(Mandatory = $True)] 11 | [string] 12 | $itemName, 13 | 14 | [Parameter(Mandatory = $True)] 15 | [string] 16 | $itemType, 17 | 18 | [Parameter(Mandatory = $True)] 19 | [string] 20 | $folderPath, 21 | 22 | [string] 23 | $reportPortalUri 24 | ) 25 | 26 | $item = (Get-RsRestItem -reportPortalUri $reportPortalUri -RsItem "$($folderPath)/$($itemName)" ) | Where-Object { $_.Type -eq $itemType -and $_.Name -eq $itemName } 27 | $item | Should Not BeNullOrEmpty 28 | } 29 | 30 | Describe "Remove-RsRestCacheRefreshPlan" { 31 | $rsFolderPath = "" 32 | $localPath = (Get-Item -Path ".\").FullName + '\Tests\CatalogItems\testResources' 33 | 34 | BeforeEach { 35 | $folderName = 'SUT_WriteRsRestCatalogItem_' + [guid]::NewGuid() 36 | New-RsRestFolder -ReportPortalUri $reportPortalUri -RsFolder / -FolderName $folderName -Verbose 37 | $rsFolderPath = '/' + $folderName 38 | $itemPath = $localPath + '\ReportCatalog.pbix' 39 | Write-RsRestCatalogItem -ReportPortalUri $reportPortalUri -Path $itemPath -RsFolder $rsFolderPath -Verbose 40 | VerifyCatalogItemExists -itemName 'ReportCatalog' -itemType 'PowerBIReport' -folderPath $rsFolderPath -reportPortalUri $reportPortalUri 41 | 42 | $dataSources = Get-RsRestItemDataSource -RsItem "$($rsFolderPath)/ReportCatalog" -ReportPortalUri $reportPortalUri 43 | $dataSources[0].DataModelDataSource.AuthType = 'UsernamePassword' 44 | $dataSources[0].DataModelDataSource.Username = 'PBIRS' 45 | $dataSources[0].DataModelDataSource.Secret = 'password' 46 | Set-RsRestItemDataSource -RsItem "$($rsFolderPath)/ReportCatalog" -ReportPortalUri $reportPortalUri -DataSources $dataSources -RsItemType 'PowerBIReport' 47 | New-RsRestCacheRefreshPlan -RsItem "$($rsFolderPath)/ReportCatalog" -ReportPortalUri $reportPortalUri -Description 'My New Refresh Plan' -Verbose 48 | 49 | } 50 | 51 | AfterEach { 52 | Remove-RsRestCatalogItem -ReportPortalUri $reportPortalUri -RsItem $rsFolderPath -Confirm:$false 53 | } 54 | 55 | Context "ReportPortalUri parameter" { 56 | 57 | It "Should remove a CacheRefreshPlan plan for a PBIX report" { 58 | Remove-RsRestCacheRefreshPlan -ReportPortalUri $reportPortalUri -RsReport "$($rsFolderPath)/ReportCatalog" 59 | 60 | $plan = Get-RsCacheRefreshPlan -ReportPortalUri $reportPortalUri -RsReport "$($rsFolderPath)/ReportCatalog" 61 | $plan | Should BeNullOrEmpty 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /Tests/CatalogItems/Rest/Remove-RsRestFolder.Tests.ps1: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2016 Microsoft Corporation. All Rights Reserved. 2 | # Licensed under the MIT License (MIT) 3 | 4 | $reportPortalUri = if ($env:PesterPortalUrl -eq $null) { 'http://localhost/reports' } else { $env:PesterPortalUrl } 5 | $reportServerUri = if ($env:PesterServerUrl -eq $null) { 'http://localhost/reportserver' } else { $env:PesterServerUrl } 6 | 7 | function VerifyCatalogItemDoesNotExists() 8 | { 9 | param( 10 | [Parameter(Mandatory = $True)] 11 | [string] 12 | $itemName, 13 | 14 | [Parameter(Mandatory = $True)] 15 | [string] 16 | $itemType, 17 | 18 | [Parameter(Mandatory = $True)] 19 | [string] 20 | $folderPath, 21 | 22 | [string] 23 | $reportServerUri 24 | ) 25 | 26 | $item = (Get-RsFolderContent -ReportServerUri $reportServerUri -RsFolder $folderPath) | Where { $_.TypeName -eq $itemType -and $_.Name -eq $itemName } 27 | $item | Should BeNullOrEmpty 28 | } 29 | 30 | Describe "Remove-RsRestFolder" { 31 | $rsFolderPath = "" 32 | 33 | BeforeEach { 34 | # creating a new folder 35 | $folderName = "SUT_RemoveRsRestFolder_" + [Guid]::NewGuid() 36 | New-RsRestFolder -ReportPortalUri $reportPortalUri -FolderName $folderName -RsFolder / 37 | $rsFolderPath = "/$folderName" 38 | 39 | # uploading resources to the folder 40 | $localResourcesPath = (Get-Item -Path ".\").FullName + '\Tests\CatalogItems\testResources' 41 | Write-RsRestFolderContent -ReportPortalUri $reportPortalUri -Path $localResourcesPath -RsFolder $rsFolderPath 42 | } 43 | 44 | Context "ReportPortalUri parameter" { 45 | It "Should delete a folder" { 46 | Remove-RsRestFolder -ReportPortalUri $reportPortalUri -RsFolder $rsFolderPath -Verbose -Confirm:$false 47 | VerifyCatalogItemDoesNotExists -itemType "Folder" -itemName $folderName -folderPath "/" -reportServerUri $reportServerUri 48 | } 49 | } 50 | 51 | Context "WebSession parameter" { 52 | $webSession = $null 53 | 54 | BeforeEach { 55 | $webSession = New-RsRestSession -ReportPortalUri $reportPortalUri 56 | } 57 | 58 | It "Should delete a folder" { 59 | Remove-RsRestFolder -WebSession $webSession -RsFolder $rsFolderPath -Verbose -Confirm:$false 60 | VerifyCatalogItemDoesNotExists -itemType "Folder" -itemName $folderName -folderPath "/" -reportServerUri $reportServerUri 61 | } 62 | } 63 | } -------------------------------------------------------------------------------- /Tests/CatalogItems/Rest/Set-RsRestItemDataModelParameters.Tests.ps1: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2017 Microsoft Corporation. All Rights Reserved. 2 | # Licensed under the MIT License (MIT) 3 | 4 | $reportPortalUri = if ($env:PesterPortalUrl -eq $null) { 'http://localhost/reports' } else { $env:PesterPortalUrl } 5 | 6 | Describe "Set-RsRestItemDataModelParameter" { 7 | $session = $null 8 | $rsFolderPath = "" 9 | $sqlPowerBIReport = "" 10 | 11 | BeforeEach { 12 | $session = New-RsRestSession -ReportPortalUri $reportPortalUri 13 | 14 | # creating test folder 15 | $folderName = 'SUT_SetRsRestItemDataModelParameters_' + [guid]::NewGuid() 16 | New-RsRestFolder -WebSession $session -RsFolder / -FolderName $folderName 17 | $rsFolderPath = '/' + $folderName 18 | 19 | # uploading test artifacts: dataModelParametersReport.rdl and DataModelParameters.pbix 20 | $localPath = (Get-Item -Path ".\").FullName + '\Tests\CatalogItems\testResources' 21 | 22 | Write-RsRestCatalogItem -WebSession $session -Path "$localPath\DataModelParameters.pbix" -RsFolder $rsFolderPath 23 | $sqlPowerBIReport = "$rsFolderPath/DataModelParameters" 24 | } 25 | 26 | AfterEach { 27 | # deleting test folder 28 | Remove-RsRestFolder -WebSession $session -RsFolder $rsFolderPath -Confirm:$false 29 | } 30 | 31 | Context "ReportPortalUri parameter" { 32 | It "fetches parameters for power bi reports" { 33 | $dataModelParameters = Get-RsRestItemDataModelParameter -ReportPortalUri $reportPortalUri -RsItem $sqlPowerBIReport -Verbose 34 | $dataModelParameters[0].Value = "NewValue" 35 | 36 | Set-RsRestItemDataModelParameter -ReportPortalUri $reportPortalUri -RsItem $sqlPowerBIReport -DataModelParameters $dataModelParameters -Verbose 37 | 38 | $dataModelParameters = Get-RsRestItemDataModelParameter -ReportPortalUri $reportPortalUri -RsItem $sqlPowerBIReport -Verbose 39 | $dataModelParameters[0].Value | Should Be "NewValue" 40 | } 41 | } 42 | 43 | Context "WebSession parameter" { 44 | $rsSession = $null 45 | 46 | BeforeEach { 47 | $rsSession = New-RsRestSession -ReportPortalUri $reportPortalUri 48 | } 49 | 50 | It "fetches data sources for power bi reports" { 51 | $dataModelParameters = Get-RsRestItemDataModelParameter -WebSession $rsSession -RsItem $sqlPowerBIReport -Verbose 52 | $dataModelParameters[0].Value = "NewValue" 53 | 54 | Set-RsRestItemDataModelParameter -WebSession $rsSession -RsItem $sqlPowerBIReport -DataModelParameters $dataModelParameters -Verbose 55 | 56 | $dataModelParameters = Get-RsRestItemDataModelParameter -WebSession $rsSession -RsItem $sqlPowerBIReport -Verbose 57 | $dataModelParameters[0].Value | Should Be "NewValue" 58 | } 59 | } 60 | } -------------------------------------------------------------------------------- /Tests/CatalogItems/Rest/Start-RsRestCacheRefreshPlan.Tests.ps1: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021 Microsoft Corporation. All Rights Reserved. 2 | # Licensed under the MIT License (MIT) 3 | 4 | $reportPortalUri = if ($env:PesterPortalUrl -eq $null) { 'http://localhost/reports' } else { $env:PesterPortalUrl } 5 | $reportServerUri = if ($env:PesterServerUrl -eq $null) { 'http://localhost/reportserver' } else { $env:PesterServerUrl } 6 | 7 | function VerifyCatalogItemExists() 8 | { 9 | param( 10 | [Parameter(Mandatory = $True)] 11 | [string] 12 | $itemName, 13 | 14 | [Parameter(Mandatory = $True)] 15 | [string] 16 | $itemType, 17 | 18 | [Parameter(Mandatory = $True)] 19 | [string] 20 | $folderPath, 21 | 22 | [string] 23 | $reportPortalUri 24 | ) 25 | 26 | $item = (Get-RsRestItem -reportPortalUri $reportPortalUri -RsItem "$($folderPath)/$($itemName)" ) | Where-Object { $_.Type -eq $itemType -and $_.Name -eq $itemName } 27 | $item | Should Not BeNullOrEmpty 28 | } 29 | 30 | Describe "Start-RsRestCacheRefreshPlan" { 31 | $rsFolderPath = "" 32 | $localPath = (Get-Item -Path ".\").FullName + '\Tests\CatalogItems\testResources' 33 | 34 | BeforeEach { 35 | $folderName = 'SUT_WriteRsRestCatalogItem_' + [guid]::NewGuid() 36 | New-RsRestFolder -ReportPortalUri $reportPortalUri -RsFolder / -FolderName $folderName -Verbose 37 | $rsFolderPath = '/' + $folderName 38 | $itemPath = $localPath + '\ReportCatalog.pbix' 39 | Write-RsRestCatalogItem -ReportPortalUri $reportPortalUri -Path $itemPath -RsFolder $rsFolderPath -Verbose 40 | VerifyCatalogItemExists -itemName 'ReportCatalog' -itemType 'PowerBIReport' -folderPath $rsFolderPath -reportPortalUri $reportPortalUri 41 | 42 | $dataSources = Get-RsRestItemDataSource -RsItem "$($rsFolderPath)/ReportCatalog" -ReportPortalUri $reportPortalUri 43 | $dataSources[0].DataModelDataSource.AuthType = 'UsernamePassword' 44 | $dataSources[0].DataModelDataSource.Username = 'PBIRS' 45 | $dataSources[0].DataModelDataSource.Secret = 'password' 46 | Set-RsRestItemDataSource -RsItem "$($rsFolderPath)/ReportCatalog" -ReportPortalUri $reportPortalUri -DataSources $dataSources -RsItemType 'PowerBIReport' 47 | New-RsRestCacheRefreshPlan -RsItem "$($rsFolderPath)/ReportCatalog" -ReportPortalUri $reportPortalUri -Description 'My New Refresh Plan' -Verbose 48 | 49 | } 50 | 51 | AfterEach { 52 | Remove-RsRestCatalogItem -ReportPortalUri $reportPortalUri -RsItem $rsFolderPath -Confirm:$false 53 | } 54 | 55 | Context "ReportPortalUri parameter" { 56 | 57 | It "Should retrieve a CacheRefreshPlan plan for a PBIX report" { 58 | Start-RsRestCacheRefreshPlan -ReportPortalUri $reportPortalUri -RsReport "$($rsFolderPath)/ReportCatalog" 59 | 60 | $plan = Get-RsCacheRefreshPlan -ReportPortalUri $reportPortalUri -RsReport "$($rsFolderPath)/ReportCatalog" 61 | $plan | Should Not BeNullOrEmpty 62 | $plan.LastStatus | Should Not Be 'New Scheduled Refresh Plan' 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /Tests/CatalogItems/TestProjects/SQLServerPerformanceDashboardReportingSolution/PerfDashboard.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2012 4 | Project("{F14B399A-7131-4C87-9E4B-1186C45EF12D}") = "SQL Server Performance Dashboard", "SQL Server Performance Dashboard\SQL Server Performance Dashboard.rptproj", "{280F4418-C6F5-4763-8CA4-63AD770AFB58}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Default = Debug|Default 9 | DebugLocal|Default = DebugLocal|Default 10 | Release|Default = Release|Default 11 | EndGlobalSection 12 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 13 | {280F4418-C6F5-4763-8CA4-63AD770AFB58}.Debug|Default.ActiveCfg = Debug 14 | {280F4418-C6F5-4763-8CA4-63AD770AFB58}.Debug|Default.Build.0 = Debug 15 | {280F4418-C6F5-4763-8CA4-63AD770AFB58}.Debug|Default.Deploy.0 = Debug 16 | {280F4418-C6F5-4763-8CA4-63AD770AFB58}.DebugLocal|Default.ActiveCfg = DebugLocal 17 | {280F4418-C6F5-4763-8CA4-63AD770AFB58}.DebugLocal|Default.Build.0 = DebugLocal 18 | {280F4418-C6F5-4763-8CA4-63AD770AFB58}.Release|Default.ActiveCfg = Release 19 | {280F4418-C6F5-4763-8CA4-63AD770AFB58}.Release|Default.Build.0 = Release 20 | {280F4418-C6F5-4763-8CA4-63AD770AFB58}.Release|Default.Deploy.0 = Release 21 | EndGlobalSection 22 | GlobalSection(SolutionProperties) = preSolution 23 | HideSolutionNode = FALSE 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /Tests/CatalogItems/testResources/DataModelParameters.pbix: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/ReportingServicesTools/ed65fb36c2a9ff352182d708d167317b0b42e9dd/Tests/CatalogItems/testResources/DataModelParameters.pbix -------------------------------------------------------------------------------- /Tests/CatalogItems/testResources/NewExcelWorkbook.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/ReportingServicesTools/ed65fb36c2a9ff352182d708d167317b0b42e9dd/Tests/CatalogItems/testResources/NewExcelWorkbook.xlsx -------------------------------------------------------------------------------- /Tests/CatalogItems/testResources/NewKPI.kpi: -------------------------------------------------------------------------------- 1 | { 2 | "Data": { 3 | "Value": { 4 | "@odata.type": "#Model.KpiStaticDataItem", 5 | "Type": "Static", 6 | "Value": "513120" 7 | }, 8 | "Goal": null, 9 | "Status": { 10 | "@odata.type": "#Model.KpiStaticDataItem", 11 | "Type": "Static", 12 | "Value": "1" 13 | }, 14 | "TrendSet": { 15 | "@odata.type": "#Model.KpiStaticDataItem", 16 | "Type": "Static", 17 | "Value": "[7.0,6.0,1.0,7.0,2.0,6.0,5.0,9.0]" 18 | } 19 | }, 20 | "Description": null, 21 | "DrillthroughTarget": null, 22 | "Hidden": false, 23 | "IsFavorite": false, 24 | "Name": "NewKPI", 25 | "@odata.type": "#Model.Kpi", 26 | "Path": "/NewKPI", 27 | "Type": "Kpi", 28 | "ValueFormat": "General", 29 | "Values": { 30 | "Value": "513120", 31 | "Goal": null, 32 | "Status": 1.0, 33 | "TrendSet": [ 34 | 7.0, 35 | 6.0, 36 | 1.0, 37 | 7.0, 38 | 2.0, 39 | 6.0, 40 | 5.0, 41 | 9.0 42 | ] 43 | }, 44 | "Visualization": "Bar" 45 | } -------------------------------------------------------------------------------- /Tests/CatalogItems/testResources/OldExcelWorkbook.xls: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/ReportingServicesTools/ed65fb36c2a9ff352182d708d167317b0b42e9dd/Tests/CatalogItems/testResources/OldExcelWorkbook.xls -------------------------------------------------------------------------------- /Tests/CatalogItems/testResources/ReportCatalog.pbix: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/ReportingServicesTools/ed65fb36c2a9ff352182d708d167317b0b42e9dd/Tests/CatalogItems/testResources/ReportCatalog.pbix -------------------------------------------------------------------------------- /Tests/CatalogItems/testResources/SimplePowerBIReport.pbix: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/ReportingServicesTools/ed65fb36c2a9ff352182d708d167317b0b42e9dd/Tests/CatalogItems/testResources/SimplePowerBIReport.pbix -------------------------------------------------------------------------------- /Tests/CatalogItems/testResources/SqlPowerBIReport.pbix: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/ReportingServicesTools/ed65fb36c2a9ff352182d708d167317b0b42e9dd/Tests/CatalogItems/testResources/SqlPowerBIReport.pbix -------------------------------------------------------------------------------- /Tests/CatalogItems/testResources/SutWriteRsFolderContent_DataSource.rsds: -------------------------------------------------------------------------------- 1 | SQLData Source=localhost;Initial Catalog=ReportServerFalseFalseNoneTrue -------------------------------------------------------------------------------- /Tests/CatalogItems/testResources/UnDataset.rsd: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | /ds/ref 6 | select 'Alejandra' AS Name, 'Jaramillo' As LastName 7 | union 8 | select 'Barry' AS Name, 'Alen' As LastName 9 | union 10 | select 'Carlos' AS Name, 'Strange' As LastName 11 | true 12 | 13 | 14 | 15 | Name 16 | System.String 17 | 18 | 19 | LastName 20 | System.String 21 | 22 | 23 | 24 | http://localhost/ReportServer 25 | -------------------------------------------------------------------------------- /Tests/CatalogItems/testResources/datasources/noDatasourcesReport.rdl: -------------------------------------------------------------------------------- 1 |  2 | 3 | Segoe UI 4 | 0 5 | 6 | 7 | 8 | 9 | 10 | true 11 | true 12 | 13 | 14 | 15 | 16 | 17 | 21 | 22 | 23 | 33 | 34 | 2pt 35 | 2pt 36 | 2pt 37 | 2pt 38 | 39 | 40 | 41 | 2.25in 42 | 45 | 46 | 47 | 48 | 6in 49 | 50 | 51 | 0.45in 52 | true 53 | true 54 | 55 | 56 | true 57 | true 58 | 59 | 60 | 61 | 62 | =Globals!ExecutionTime 63 | 69 | 70 | 71 | ExecutionTime 72 | 0.2in 73 | 4in 74 | 0.25in 75 | 2in 76 | 79 | 80 | 2pt 81 | 2pt 82 | 2pt 83 | 2pt 84 | 85 | 86 | 87 | 90 | 91 | 92 | 93 | 1in 94 | 1in 95 | 1in 96 | 1in 97 | 33 | 34 | 35 | 45 | 46 | 2pt 47 | 2pt 48 | 2pt 49 | 2pt 50 | 51 | 52 | 53 | 2.25in 54 | 57 | 58 | 59 | 60 | 6in 61 | 62 | 63 | 0.45in 64 | true 65 | true 66 | 67 | 68 | true 69 | true 70 | 71 | 72 | 73 | 74 | =Globals!ExecutionTime 75 | 81 | 82 | 83 | ExecutionTime 84 | 0.2in 85 | 4in 86 | 0.25in 87 | 2in 88 | 91 | 92 | 2pt 93 | 2pt 94 | 2pt 95 | 2pt 96 | 97 | 98 | 99 | 102 | 103 | 104 | 105 | 1in 106 | 1in 107 | 1in 108 | 1in 109 |