From d48a3dd98886f4bb9f49fe945597c93fbeea33a9 Mon Sep 17 00:00:00 2001 From: selsine Date: Thu, 18 Feb 2021 15:05:04 -0700 Subject: [PATCH 1/2] Added the FileExtensionsToUpload parameter to control which file types from the folder are uploaded. --- .../CatalogItems/Write-RsFolderContent.ps1 | 31 +++++++++++++------ 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/ReportingServicesTools/Functions/CatalogItems/Write-RsFolderContent.ps1 b/ReportingServicesTools/Functions/CatalogItems/Write-RsFolderContent.ps1 index e9ba842a..75c41651 100644 --- a/ReportingServicesTools/Functions/CatalogItems/Write-RsFolderContent.ps1 +++ b/ReportingServicesTools/Functions/CatalogItems/Write-RsFolderContent.ps1 @@ -37,6 +37,10 @@ function Write-RsFolderContent Use "New-RsWebServiceProxy" to generate a proxy object for reuse. Useful when repeatedly having to connect to multiple different Report Server. + .PARAMETER FileExtensionsToUpload + An array of file extensions to upload. + Useful when Reports and Data Sources are stored in the same folder on disk, but a different + folder on the server. E.g. -FileExtensionsToUpload @(".rsds", ".rsd", ".rds") .EXAMPLE Write-RsFolderContent -ReportServerUri 'http://localhost/reportserver_sql2012' -Path c:\monthlyreports -RsFolder /monthlyReports @@ -69,7 +73,10 @@ function Write-RsFolderContent [System.Management.Automation.PSCredential] $Credential, - $Proxy + $Proxy, + + [string[]] + $FileExtensionsToUpload = $null ) if ($PSCmdlet.ShouldProcess($Path, "Upload all contents in folder $(if ($Recurse) { "and subfolders " })to $RsFolder")) @@ -90,6 +97,14 @@ function Write-RsFolderContent { $items = Get-ChildItem $Path } + + #Create array of valid extensions to upload + $validExtensions = ".rdl", ".rsds", ".rsd", ".rds", ".jpg", ".jpeg", ".png" + if ($null -ne $FileExtensionsToUpload) + { + $validExtensions = $FileExtensionsToUpload + } + foreach ($item in $items) { if (($item.PSIsContainer) -and $Recurse) @@ -124,14 +139,8 @@ function Write-RsFolderContent throw (New-Object System.Exception("Failed to create folder '$($item.Name)' in '$parentFolder': $($_.Exception.Message)", $_.Exception)) } } - - if ($item.Extension -eq ".rdl" -or - $item.Extension -eq ".rsds" -or - $item.Extension -eq ".rsd" -or - $item.Extension -eq ".rds" -or - $item.Extension -eq ".jpg" -or - $item.Extension -eq ".jpeg" -or - $item.Extension -eq ".png" ) + + if ($validExtensions.Contains($item.Extension)) { $relativePath = Clear-Substring -string $item.FullName -substring $sourceFolder.FullName.TrimEnd("\") -position front $relativePath = Clear-Substring -string $relativePath -substring ("\" + $item.Name) -position back @@ -155,6 +164,10 @@ function Write-RsFolderContent throw (New-Object System.Exception("Failed to create catalog item from '$($item.FullName)' in '$parentFolder': $($_.Exception)", $_.Exception)) } } + else + { + Write-Verbose "Ignoring $($item.FullName) due to extension" + } } } } From 7b2f8015a323501eef37791f5c4d0e85a8ba916b Mon Sep 17 00:00:00 2001 From: selsine Date: Fri, 26 Mar 2021 07:54:19 -0600 Subject: [PATCH 2/2] Added an addition example using FileExtensionsToUpload --- .../Functions/CatalogItems/Write-RsFolderContent.ps1 | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/ReportingServicesTools/Functions/CatalogItems/Write-RsFolderContent.ps1 b/ReportingServicesTools/Functions/CatalogItems/Write-RsFolderContent.ps1 index 75c41651..fe3053b0 100644 --- a/ReportingServicesTools/Functions/CatalogItems/Write-RsFolderContent.ps1 +++ b/ReportingServicesTools/Functions/CatalogItems/Write-RsFolderContent.ps1 @@ -47,6 +47,15 @@ function Write-RsFolderContent Description ----------- Uploads all reports under c:\monthlyreports to folder /monthlyReports. + + .EXAMPLE + Write-RsFolderContent -ReportServerUri 'http://localhost/reportserver_sql2012' -Path c:\Reports -RsFolder '/dataSources' -FileExtensionsToUpload @(".rsds", ".rsd", ".rds") + + Write-RsFolderContent -ReportServerUri 'http://localhost/reportserver_sql2012' -Path c:\Reports -RsFolder '/monthlyReports' -FileExtensionsToUpload @(".rsdl") + + Description + ----------- + Uploads all data sources under c:\monthlyreports to folder /dataSources and then all reports under c:\monthlyreports to folder /monthlyReports #> [CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'Medium')] param(