【发布时间】:2014-03-21 16:06:15
【问题描述】:
我们正在尝试自动将 SQL Server 报告从多台速度较慢的服务器迁移到一台速度更快的服务器。我们需要一次移动一个客户。我们有一个脚本可以导出所有报告、数据源和文件夹结构。
如果文件夹结构到位,我们已设法修改脚本以重新创建所有数据源和报告文件。我们以这篇文章为基础
我们无法实现的是自动重新创建文件夹结构。
我们的脚本创建了一个文件夹列表,如下所示:
\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
我们可以将 \ 反转为 / 并使用拆分路径收集每个文件夹路径的部分。
每个客户端都有不同的文件夹路径,每个客户端的子文件夹数量也不同。
我们知道我们需要创建一个文件夹 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 技能都是自学的,所以请原谅我们代码中的任何粗鲁。
问候
斯宾塞
【问题讨论】:
标签: powershell reporting-services ssrs-2012