简体   繁体   English

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

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

We are trying to automate the migration of SQL server reports from a number of slow servers to one much faster server. 我们正在尝试自动将SQL Server报告从许多慢速服务器迁移到一个快得多的服务器。 We need to move our clients one at a time. 我们需要一次移动一个客户。 We have a script that exports all of the reports, data sources and the folder structure. 我们有一个脚本,可以导出所有报告,数据源和文件夹结构。

we have managed to amend scripts to recreate all the data sources and report files if the folder structure is in place. 如果文件夹结构到位,我们已经设法修改了脚本以重新创建所有数据源和报告文件。 We took this article as a basis 我们以本文为基础

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

what we are unable to achieve is to automatically recreate the folder structure. 我们无法实现的是自动重新创建文件夹结构。

The script we have creates a list of folders as so: 我们拥有的脚本将这样创建一个文件夹列表:

\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

We can reverse the \\ to / and using split-path collect sections of each folder path. 我们可以将\\反转为/,然后使用split-path收集每个文件夹路径的部分。

Each client has different folder paths and the number of subfolders differs per client. 每个客户端具有不同的文件夹路径,并且每个客户端的子文件夹数也不同。

We know we need to create a folder client_live then its sub folders and so on. 我们知道我们需要创建一个文件夹client_live然后是它的子文件夹,依此类推。

The issue is how to loop through the list we have and pass the relevant details into this section of code, replacing the hardcoded entries for "NewFolder" and "/" with appropriate values from the list 问题是如何遍历我们拥有的列表,并将相关详细信息传递到此部分代码中,用列表中的适当值替换“ 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)

This is what we use to generate our list. 这就是我们用来生成列表的方式。

# 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
}

Our powershell skills are all self taught so please excuse any crudities in our code. 我们的powershell技能都是自学的,因此请原谅我们的代码中的任何粗俗之处。

regards 问候

spencer 斯宾塞

You need to create a recursive function to walk the folder structure. 您需要创建一个递归函数来遍历文件夹结构。 You have the api calls to get the properties for items in ssrs so you can use those in a function similar to: 您具有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