2016-06-28 2 views
1

여러 서버에 복사되는 보고서가 있습니다. 수동으로 가져 오며 데이터 소스 속성은 현재 서버의 사양과 일치하도록 변경됩니다. 사용자가 SSRS 보고서를 열고 PowerShell을 통해 공유 데이터 원본 속성을 동적으로 변경할 수 있도록하여 프로세스를 자동화 할 수 있기를 바랍니다. 네가 도울 수 있기를 바랍니다. 아래 참조가 나타날 수 있습니다. Powershell을 사용하여 SSRS 프로젝트 열기

The Report is located on this location:

enter image description here

스크립트

은 서버 이름, 사용자 이름과 암호를 입력 매개 변수를 받아 들일 것입니다. 또한 암호 저장에 체크 표시를해야합니다.

답변

0

나는 이것을위한 스크립트를 만들 수 있다고 믿을 수 없었다. 나중에 참조 할 수 있도록 아래 스크립트를 사용할 수 있습니다. 각 부품에 대한 설명이 가능하며 변경해야 할 부분에는 "here"키워드가 있습니다 (예 : Your_database_name_here.

Import-Module SqlPs 

#Input parameter to get Server\Instancename of your Datasource 
$Servername = Read-Host "Please enter your Servername" 
$Instancename = Read-Host "Please enter your Instancename. For default instance please press enter" 
Write-host "" 

if ($Instancename -eq ""){ 
    $ServerInstance = $Servername 
    } 
Else { 
    $ServerInstance = $Servername +"\"+ $InstanceName 
} 

#Setting up SSRS Target URL. This is the location where your reports would be deployed. 
if ($Instancename -eq ""){ 
    $ReportServerUri = "http://$Servername/ReportServer//ReportService2010.asmx?wsdl" 
    $TargetURL = "http://$Servername/Reports" 
    } 
Else { 
    $ReportServerUri = "http://$Servername/ReportServer_$Instancename//ReportService2010.asmx?wsdl" 
    $TargetURL = "http://$Servername/Reports_$Instancename" 
} 

$global:proxy = New-WebServiceProxy -Uri $ReportServerUri -UseDefaultCreden 



#We would make use of SQL Server Authentication for the reports shared datasource so you need to supply a username and password. 
Write-Host "  SQL Server Authentication:" 
$Username = Read-Host "  Username" 
$Password = Read-Host -AsSecureString "Password" 


$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("Reports”, “/”, $properties); 
$newFolder = $proxy.CreateFolder("Data Sources”, “/”, $properties); 

$Children =$proxy.ListChildren("/",$false) 
$DBname = 'Your_Database_Name_Here' 


# Creating Datasource through powershell 
Write-Host "  Creating Datasource ..." 
$Name = "Name_Your_Datasource_here" 
$Parent = "/Data Sources" 
$ConnectString = "data source=$Servername\$Instancename;initial catalog=$DBname" 
$type = $Proxy.GetType().Namespace 
$DSDdatatype = ($type + '.DataSourceDefinition') 
$DSD = new-object ($DSDdatatype) 
if($DSD -eq $null){ 
     Write-Error Failed to create data source definition object 
} 
$CredentialDataType = ($type + '.CredentialRetrievalEnum') 
$Cred = new-object ($CredentialDataType) 
$CredEnum = ($CredentialDataType).Integrated 
$Cred.value__=1 

$DSD.CredentialRetrieval =$Cred 
$DSD.ConnectString = $ConnectString 
$DSD.Enabled = $true 
$DSD.EnabledSpecified = $false 
$DSD.Extension = "SQL" 
$DSD.ImpersonateUserSpecified = $false 
$DSD.Prompt = $null 
$DSD.WindowsCredentials = $false 
$DSD.UserName = $Username 
$DSD.Password = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($Password)) 

$newDSD = $proxy.CreateDataSource($Name,$Parent,$true,$DSD,$null) 

#Deploying RLD files to Target URL 
Write-Host "  Deploying RDL files ..." 
$stream = Get-Content 'D:\Your_RDL_path_here.rdl' -Encoding byte 
$warnings [email protected](); 
$proxy.CreateCatalogItem("Report","Report_Name_here","/Reports",$true,$stream,$null,[ref]$warnings) 


#Let's make use of the datasource we just created for your RDL files. 
$Items = $global:proxy.listchildren("/Data Sources", $true) 
foreach ($item in $items) 
{ 

$DatasourceName = $item.Name 
$DatasourcePath = $item.Path 
} 


$RDLS = $global:proxy.listchildren("/Reports", $true) 
foreach ($rdl in $rdls) 
{ 
$report = $rdl.path 


$rep = $global:proxy.GetItemDataSources($report) 
$rep | ForEach-Object { 
$proxyNamespace = $_.GetType().Namespace 
    $constDatasource = New-Object ("$proxyNamespace.DataSource") 
    $constDatasource.Name = $DataSourceName 
    $constDatasource.Item = New-Object ("$proxyNamespace.DataSourceReference") 
    $constDatasource.Item.Reference = $DataSourcePath 

$_.item = $constDatasource.Item 
$global:proxy.SetItemDataSources($report, $_) 
Write-Host "Changing datasource `"$($_.Name)`" to $($_.Item.Reference)" 
} 
} 

#Open a IE browser to view the report. 
$IE=new-object -com internetexplorer.application 
$IE.navigate2($TargetURL) 
$IE.visible=$true 
Write-Host ""  
Write-Host "You may now view the Reports through the open IE browser." 
Write-Host -ForegroundColor Green "**STEP COMPLETED!"