Skip to content

Commit 383ecb2

Browse files
Rob SewellRob Sewell
Rob Sewell
authored and
Rob Sewell
committed
only with one datasource
1 parent 6249aff commit 383ecb2

File tree

1 file changed

+27
-21
lines changed

1 file changed

+27
-21
lines changed

PublishPBIXFile.ps1

+27-21
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
<#PSScriptInfo
33
4-
.VERSION 1.0.0.0
4+
.VERSION 1.0.0.1
55
66
.GUID 0b89f8fb-6de5-4f1b-8a0d-6172a89d4743
77
@@ -114,6 +114,7 @@ $ConnectionString = "Server001;dbachecks"
114114
.NOTES
115115
Rob Sewell 20/08/2018
116116
#>
117+
117118
function Publish-PBIXFile {
118119
[CmdletBinding(DefaultParameterSetName = 'ByUserName', SupportsShouldProcess)]
119120
Param(
@@ -153,7 +154,7 @@ function Publish-PBIXFile {
153154

154155
# create folder (optional)
155156
try {
156-
if ($PSCmdlet.ShouldProcess("$ReportServerURI","Creating a folder called $FolderName at $FolderLocation")){
157+
if ($PSCmdlet.ShouldProcess("$ReportServerURI", "Creating a folder called $FolderName at $FolderLocation")) {
157158
$Null = New-RsRestFolder -WebSession $session -RsFolder $FolderLocation -FolderName $FolderName -ErrorAction Stop
158159
}
159160
}
@@ -168,9 +169,9 @@ function Publish-PBIXFile {
168169
}
169170

170171
try {
171-
if ($PSCmdlet.ShouldProcess("$ReportServerURI","Uploading the pbix from $PBIXFile to the report server ")){
172-
# upload copy of PBIX to new folder
173-
Write-RsRestCatalogItem -WebSession $session -Path $PBIXFile -RsFolder $folderPath -Description $Description -Overwrite
172+
if ($PSCmdlet.ShouldProcess("$ReportServerURI", "Uploading the pbix from $PBIXFile to the report server ")) {
173+
# upload copy of PBIX to new folder
174+
Write-RsRestCatalogItem -WebSession $session -Path $PBIXFile -RsFolder $folderPath -Description $Description -Overwrite
174175
}
175176
}
176177
catch {
@@ -181,7 +182,7 @@ function Publish-PBIXFile {
181182
try {
182183
Write-Verbose "Getting the datasources from the pbix file for updating"
183184
# get data source object
184-
$dataSource = Get-RsRestItemDataSource -WebSession $session -RsItem "$FolderPath/$PBIXName"
185+
$datasources = Get-RsRestItemDataSource -WebSession $session -RsItem "$FolderPath/$PBIXName"
185186
Write-Verbose "Got the datasources for updating"
186187
}
187188
catch {
@@ -192,30 +193,35 @@ function Publish-PBIXFile {
192193

193194
try {
194195
Write-Verbose "Updating Datasource"
195-
# change connection string (to point at new source)
196-
$dataSource.ConnectionString = $ConnectionString
197196

198-
if ($Credential -or $UserName) {
199-
if ($Credential) {
200-
$UserName = $Credential.UserName
201-
$Password = $Credential.GetNetworkCredential().Password
197+
198+
foreach ($dataSource in $datasources) {
199+
if ($ConnectionString) {
200+
# change connection string (to point at new source)
201+
$dataSource.ConnectionString = $ConnectionString
202202
}
203-
else {
204-
$UserName = $ConnectionUserName
205-
$Password = $Secret
203+
if ($Credential -or $UserName) {
204+
if ($Credential) {
205+
$UserName = $Credential.UserName
206+
$Password = $Credential.GetNetworkCredential().Password
207+
}
208+
else {
209+
$UserName = $ConnectionUserName
210+
$Password = $Secret
211+
}
212+
$dataSource.CredentialRetrieval = 'Store'
213+
$dataSource.DataModelDataSource.Username = $UserName
214+
$dataSource.DataModelDataSource.Secret = $Password
206215
}
207-
$dataSource.CredentialRetrieval = 'Store'
208-
$dataSource.DataModelDataSource.Username = $UserName
209-
$dataSource.DataModelDataSource.Secret = $Password
210-
}
211-
if ($PSCmdlet.ShouldProcess("$ReportServerURI","Updating the data source for the report $PBIXName")){
216+
if ($PSCmdlet.ShouldProcess("$ReportServerURI", "Updating the data source for the report $PBIXName")) {
212217
# update data source object on server
213218
Set-RsRestItemDataSource -WebSession $session -RsItem "$folderPath/$PBIXName" -RsItemType PowerBIReport -DataSources $datasource
219+
}
214220
}
215221
}
216222
catch {
217223
Write-Warning "Failed to set the datasource"
218224
Return
219225
}
220226
Write-Verbose "Completed Successfully"
221-
}
227+
}

0 commit comments

Comments
 (0)