1
1
2
2
<# PSScriptInfo
3
3
4
- .VERSION 1.0.0.0
4
+ .VERSION 1.0.0.1
5
5
6
6
.GUID 0b89f8fb-6de5-4f1b-8a0d-6172a89d4743
7
7
@@ -114,6 +114,7 @@ $ConnectionString = "Server001;dbachecks"
114
114
. NOTES
115
115
Rob Sewell 20/08/2018
116
116
#>
117
+
117
118
function Publish-PBIXFile {
118
119
[CmdletBinding (DefaultParameterSetName = ' ByUserName' , SupportsShouldProcess )]
119
120
Param (
@@ -153,7 +154,7 @@ function Publish-PBIXFile {
153
154
154
155
# create folder (optional)
155
156
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 " )) {
157
158
$Null = New-RsRestFolder - WebSession $session - RsFolder $FolderLocation - FolderName $FolderName - ErrorAction Stop
158
159
}
159
160
}
@@ -168,9 +169,9 @@ function Publish-PBIXFile {
168
169
}
169
170
170
171
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
174
175
}
175
176
}
176
177
catch {
@@ -181,7 +182,7 @@ function Publish-PBIXFile {
181
182
try {
182
183
Write-Verbose " Getting the datasources from the pbix file for updating"
183
184
# get data source object
184
- $dataSource = Get-RsRestItemDataSource - WebSession $session - RsItem " $FolderPath /$PBIXName "
185
+ $datasources = Get-RsRestItemDataSource - WebSession $session - RsItem " $FolderPath /$PBIXName "
185
186
Write-Verbose " Got the datasources for updating"
186
187
}
187
188
catch {
@@ -192,30 +193,35 @@ function Publish-PBIXFile {
192
193
193
194
try {
194
195
Write-Verbose " Updating Datasource"
195
- # change connection string (to point at new source)
196
- $dataSource.ConnectionString = $ConnectionString
197
196
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
202
202
}
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
206
215
}
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 " )) {
212
217
# update data source object on server
213
218
Set-RsRestItemDataSource - WebSession $session - RsItem " $folderPath /$PBIXName " - RsItemType PowerBIReport - DataSources $datasource
219
+ }
214
220
}
215
221
}
216
222
catch {
217
223
Write-Warning " Failed to set the datasource"
218
224
Return
219
225
}
220
226
Write-Verbose " Completed Successfully"
221
- }
227
+ }
0 commit comments