Sql-Server

如何在 Reporting Services 伺服器的每個文件夾中列出 SSRS 權限?

  • February 21, 2020

我有以下 powershell 腳本,可從報告服務伺服器下載所有RDL

我不是我非常感謝的作者。它對於下載 RDL 非常有用。

#note this is tested on PowerShell v2 and SSRS 2008 R2
#marcelo miorelli
#23-oct-2018
#How to Download All Your SSRS Report Definitions (RDL files) Using PowerShell
#Written by belle

#Here’s a short PowerShell script that :
#1. Connects to your report server
#2. Creates the same folder structure you have in your Report Server
#3. Download all the SSRS Report Definition (RDL) files into their respective folders

#In addition to backing up your Source Project, your ReportServer database, or good old RSScripter 
#(see http://sqlserver-indo.org/blogs/mca/archive/2009/03/08/extract-and-transfer-rdl-files-from-ssrs.aspx) 
#this is just another way you can “backup” or archive your reports.


[void][System.Reflection.Assembly]::LoadWithPartialName("System.Xml.XmlDocument");
[void][System.Reflection.Assembly]::LoadWithPartialName("System.IO");

$ReportServerUri = "http://qg-v-sqlrs-pr/Reportserver/Reportservice2005.asmx"      #"http://yourreportserver/ReportServer/ReportService2005.asmx";
$Proxy = New-WebServiceProxy -Uri $ReportServerUri -Namespace SSRS.ReportingService2005 -UseDefaultCredential ;

#check out all members of $Proxy
#$Proxy | Get-Member
#http://msdn.microsoft.com/en-us/library/aa225878(v=SQL.80).aspx

#second parameter means recursive
$items = $Proxy.ListChildren("/", $true) | 
        select Type, Path, ID, Name | 
        Where-Object {$_.type -eq "Report"};

#create a new folder where we will save the files
#PowerShell datetime format codes http://technet.microsoft.com/en-us/library/ee692801.aspx

#create a timestamped folder, format similar to 2011-Mar-28-0850PM
$folderName = Get-Date -format "yyyy-MMM-dd-hhmmtt";
$fullFolderName = "D:\SSRS_Export\" + $folderName;
[System.IO.Directory]::CreateDirectory($fullFolderName) | out-null

foreach($item in $items)
{
   #need to figure out if it has a folder name
   $subfolderName = split-path $item.Path;
   $reportName = split-path $item.Path -Leaf;
   $fullSubfolderName = $fullFolderName + $subfolderName;
   if(-not(Test-Path $fullSubfolderName))
   {
       #note this will create the full folder hierarchy
       [System.IO.Directory]::CreateDirectory($fullSubfolderName) | out-null
   }

   $rdlFile = New-Object System.Xml.XmlDocument;
   [byte[]] $reportDefinition = $null;
   $reportDefinition = $Proxy.GetReportDefinition($item.Path);

   #note here we're forcing the actual definition to be 
   #stored as a byte array
   #if you take out the @() from the MemoryStream constructor, you'll 
   #get an error
   [System.IO.MemoryStream] $memStream = New-Object System.IO.MemoryStream(@(,$reportDefinition));
   $rdlFile.Load($memStream);

   $fullReportFileName = $fullSubfolderName + "\" + $item.Name +  ".rdl";
   #Write-Host $fullReportFileName;
   $rdlFile.Save( $fullReportFileName);

}

我在這個特定伺服器上遇到的問題是顯然我沒有足夠的權限來下載報告。

我想確定我缺少權限的確切位置。我怎樣才能做到這一點?

或者,我如何列出 SSRS 中每個文件夾中的所有權限?

這是我收到的錯誤消息:

在此處輸入圖像描述

這是錯誤消息的文本:

Exception calling "GetReportDefinition" with "1" argument(s): "The permissions granted to user 'mycompany\MMiorelli' are insufficient for performing this operation. ---> 
Microsoft.ReportingServices.Diagnostics.Utilities.AccessDeniedException: The permissions granted to user 'mycompany\MMiorelli' are insufficient for performing this 
operation."
At line:62 char:5
+     $reportDefinition = $Proxy.GetReportDefinition($item.Path);
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
   + FullyQualifiedErrorId : SoapException

New-Object : Exception calling ".ctor" with "1" argument(s): "Buffer cannot be null.
Parameter name: buffer"
At line:68 char:43
+ ... memStream = New-Object System.IO.MemoryStream(@(,$reportDefinition)); ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   + CategoryInfo          : InvalidOperation: (:) [New-Object], MethodInvocationException
   + FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand

Exception calling "Load" with "1" argument(s): "Root element is missing."
At line:69 char:5
+     $rdlFile.Load($memStream);
+     ~~~~~~~~~~~~~~~~~~~~~~~~~
   + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
   + FullyQualifiedErrorId : DotNetMethodException

Exception calling "Save" with "1" argument(s): "Invalid XML document. The document does not have a root element."
At line:73 char:5
+     $rdlFile.Save( $fullReportFileName);
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
   + FullyQualifiedErrorId : DotNetMethodException

不是對這個問題的直接回答,而是作為替代方案,當然非常有用,

我遵循了Peter Vandivier在上述評論中提供的建議和連結,並對原始腳本進行了一些更改,例如如何轉換為 VARBINARY(MAX),甚至考慮過master.dbo.fn_varbintohexstr,但它太慢了。

這是修改後的腳本,它提供了所有的 RDL 文件 - 這是一個昂貴的查詢,但它似乎工作。

在我的環境中,返回 348 份報告大約需要一分鐘。我的 powershell 腳本返回 347 個報告並抱怨權限,這裡沒有抱怨權限。


use ReportServer
go

with VarBinMax as ( 
   select 
        ItemID
       ,VarBinMax    = CONVERT(VARBINARY(MAX),[Content],1)
       ,HasBom       = CONVERT(BIT,IIF(
                       LEFT(CONVERT(VARBINARY(MAX),[Content],1),3)=0xEFBBBF,1,0))
       ,LenVarBinMax = LEN(CONVERT(VARBINARY(MAX),[Content],1))
       ,[Type]
   from [Catalog]
   where [Type] = 2
) -- select top(10) * from VarBinMax
, ContentNoBom as (
   select 
        ItemID
       ,ContentNoBom = CONVERT(VARBINARY(max),
                       IIF(HasBom=1,SUBSTRING(VarBinMax,4,LenVarBinMax),VarBinMax))
   from VarBinMax
)  
--select top(10) * from ContentNoBom
select 
    ItemID
   ,RdlXml  = CONVERT(XML,ContentNoBom)
   ,RdlText = CONVERT(NVARCHAR(MAX),CONVERT(XML,ContentNoBom))
into #RDL
from ContentNoBom cnb

select * 
from #RDL

引用自:https://dba.stackexchange.com/questions/260196