繁体   English   中英

如何使用Powershell脚本创建SSRS 2012文件夹

[英]How to create SSRS 2012 folders with powershell script

我们正在尝试自动将SQL Server报告从许多慢速服务器迁移到一个快得多的服务器。 我们需要一次移动一个客户。 我们有一个脚本,可以导出所有报告,数据源和文件夹结构。

如果文件夹结构到位,我们已经设法修改了脚本以重新创建所有数据源和报告文件。 我们以本文为基础

http://sqlblogcasts.com/blogs/sqlandthelike/archive/2013/02/12/deploying-ssrs-artefacts-using-powershell-simply.aspx

我们无法实现的是自动重新创建文件夹结构。

我们拥有的脚本将这样创建一个文件夹列表:

\client_live
\client_live\AccountTransaction
\client_live\BudgetApproval
\client_live\Custom
\client_live\NominalReporting
\client_live\OnlineReports
\client_live\Product
\client_live\Sales
\client_live\Stock
\client_live\Stock\updates
\client_live\Stock\backorder
\client_live\Suppliers
\client_live\TransactionReporting
\client_live\Transactions

我们可以将\\反转为/,然后使用split-path收集每个文件夹路径的部分。

每个客户端具有不同的文件夹路径,并且每个客户端的子文件夹数也不同。

我们知道我们需要创建一个文件夹client_live然后是它的子文件夹,依此类推。

问题是如何遍历我们拥有的列表,并将相关详细信息传递到此部分代码中,用列表中的适当值替换“ NewFolder”和“ /”的硬编码条目

$type = $Proxy.GetType().Namespace
$datatype = ($type + '.Property')

$property =New-Object ($datatype);
$property.Name = “NewFolder”
$property.Value = “NewFolder”

$numproperties = 1
$properties = New-Object ($datatype + '[]')$numproperties 
$properties[0] = $property;

$newFolder = $proxy.CreateFolder(“NewFolder”, “/”, $properties)

这就是我们用来生成列表的方式。

# script to create folders in SQL 2012 RS
#
# taken from http://sqlblogcasts.com/blogs/sqlandthelike/archive/2013/02/12/deploying-ssrs-artefacts-using-powershell-simply.aspx
# and amended.
# Connect to SSRS Webservice - assume we are on the server used.
$ReportServerUri = "http://localhost/ReportServer//ReportService2010.asmx?wsdl"
$global:proxy = New-WebServiceProxy -Uri $ReportServerUri -UseDefaultCredential ;
# amend the following line to point to your files.
$source = "C:\import\Lime"
$cut=$source.length

$result=gci -r $source | ?{ $_.PSIsContainer } | % { $_.FullName }

foreach ($item in $result)
{
# first input to  to have correct data source.
$list=$item.substring($cut)
# echo out just to validate what we have so far.
echo $list
}

我们的powershell技能都是自学的,因此请原谅我们的代码中的任何粗俗之处。

问候

斯宾塞

您需要创建一个递归函数来遍历文件夹结构。 您具有api调用来获取ssrs中项目的属性,因此可以在类似于以下功能的函数中使用这些属性:

function RecurseSSRSDirectory ([string]$directory){

    $items = <--Function to get assets in $directory

    foreach ($item in $items) {
        if ($item type is report) {
            //do something with report
        }
        elseif  ($item type is dataset) {
            //do something with dataset
        }elseif ($item type is folder) {
            //Create folder here
            Recurse $item.Path
        }

    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM