Skip to content

Instantly share code, notes, and snippets.

@jklemmack
Last active June 12, 2018 18:44
Show Gist options
  • Save jklemmack/32fcdcde614d6cd8433e10509f39e9bf to your computer and use it in GitHub Desktop.
Save jklemmack/32fcdcde614d6cd8433e10509f39e9bf to your computer and use it in GitHub Desktop.
<#
# Run these two lines to download the Microsoft Powershell Tools.
Project URL: https://github.com/Microsoft/ReportingServicesTools
[Net.ServicePointManager]::SecurityProtocol = "tls12, tls11, tls"
Invoke-Expression (Invoke-WebRequest https://raw.githubusercontent.com/Microsoft/ReportingServicesTools/master/Install.ps1)
#>
function Write-ReportsToFolder {
param (
[string] $ReportServerUri,
[string] $ServerFolder,
[string] $LocalFolder
)
Write-Host 'Scanning ' $ServerFolder
$localFolders = Get-ChildItem $LocalFolder | ?{ $_.PSIsContainer } | Select-Object -Expand Name
$serverFolders = Get-RsFolderContent -ReportServerUri $ReportServerUri -RsFolder $ServerFolder | ?{$_.TypeName -eq 'Folder'} | Select-Object -Expand Name
$localReports = Get-ChildItem $LocalFolder | ?{ $_.Extension -eq '.rdl' } | Select-Object -Expand Name
$serverReports = Get-RsFolderContent -ReportServerUri $ReportServerUri -RsFolder $ServerFolder | ?{$_.TypeName -eq 'Report'} | Select-Object -ExpandProperty Name
$reportsToAdd = $localReports | ?{$serverReports -notcontains $_ }
$reportsToAdd | %{
Write-Host 'Adding report ' $_
$localPath = $LocalFolder + '\' + $_
Write-RsCatalogItem -ReportServerUri $ReportServerUri -Path $localPath -RsFolder $ServerFolder -Overwrite
}
$foldersToAdd = $localFolders | ?{$serverFolders -notcontains $_ }
$foldersToAdd | %{
Write-Host 'Adding folder ' $ServerFolder '/' $_
New-RsFolder -ReportServerUri $ReportServerUri -FolderName $_ -RsFolder $ServerFolder
}
foreach ($local in $localFolders) {
$l = $LocalFolder + '\' + $local
$r = $ServerFolder + '/' + $local
#Write-Host $r
Write-ReportFolder -ReportServerUri $ReportServerUri -ServerFolder $r -LocalFolder $l
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment