-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_rdl_datasource.ps1
67 lines (57 loc) · 1.91 KB
/
update_rdl_datasource.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#
# A long time ago, created by github.com/corelevel
#
# mapping existing DataSource values to the new values
$mapping = @{}
$mapping["Production"] = "/Data Sources/NewProduction"
$mapping["Dev"] = "/Data Sources/Dev"
# source file system folder
$SourceDirectory = "C:\Temp\Reports\"
# destination file system folder
$DestinationDirectory = "C:\Temp\Reports\!Updated\"
function UpdateDataSource
{
Param
(
[parameter(Mandatory=$true)]
[string]$SourceReportFile
)
[System.Xml.XmlDocument]$doc = [System.Xml.XmlDocument]::new()
$doc.Load($SourceDirectory + "\" + $SourceReportFile)
[System.Xml.XmlNamespaceManager]$nsManager = [System.Xml.XmlNamespaceManager]::new($doc.NameTable)
$nsManager.AddNamespace("ns", $doc.DocumentElement.NamespaceURI)
[System.Xml.XmlNodeList]$nodes = $doc.SelectNodes("/ns:Report/ns:DataSources/ns:DataSource/ns:DataSourceReference", $nsManager)
foreach ($node in $nodes)
{
$dataSource = $node.InnerText
if ([string]::IsNullOrEmpty($datasource))
{
Write-Host ("DataSource value not found. Source report file '{0}'" -f $SourceReportFile)
return
}
$newDataSource = $mapping[$dataSource]
if ([string]::IsNullOrEmpty($newDataSource))
{
Write-Host ("Mapping not found for DataSource={0}. Source report file '{1}'" -f $dataSource, $SourceReportFile)
return
}
else
{
$node.InnerText = $newDataSource
}
}
Write-Host ("Data source(s) updated for the source report file '{0}'" -f $SourceReportFile)
$doc.Save($DestinationDirectory + "\" + $SourceReportFile);
}
Clear-Host
try
{
Get-ChildItem $SourceDirectory -Filter *.rdl |
Foreach-Object {
UpdateDataSource($_.Name)
}
}
catch
{
Write-Host ($_.Exception.ToString())
}