Skip to content

Commit f3b015f

Browse files
Rob SewellRob Sewell
Rob Sewell
authored and
Rob Sewell
committed
Authentication type - connection string isnt working at the moment
1 parent 383ecb2 commit f3b015f

File tree

1 file changed

+42
-17
lines changed

1 file changed

+42
-17
lines changed

PublishPBIXFile.ps1

+42-17
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
<#PSScriptInfo
33
4-
.VERSION 1.0.0.1
4+
.VERSION 1.0.0.2
55
66
.GUID 0b89f8fb-6de5-4f1b-8a0d-6172a89d4743
77
@@ -41,16 +41,14 @@
4141

4242
Param()
4343

44-
4544
<#
4645
.SYNOPSIS
4746
Publishes a Power Bi File to a PowerBi Report Server. It will overwrite existing
4847
files.
4948
5049
.DESCRIPTION
51-
Publishes a Power Bi File to a Power Bi report Server and sets the connection
52-
string for the data source and the credential. Only works with one data source
53-
at present.It will overwrite existing files
50+
Publishes a Power Bi File to a Power Bi report Server and sets the credential for
51+
the datasources
5452
5553
.PARAMETER FolderName
5654
The Name of the folder the report is to be placed. Will be created if it doesnt
@@ -69,8 +67,8 @@ The full path to the pbix file
6967
.PARAMETER Description
7068
The Description of the report
7169
72-
.PARAMETER ConnectionString
73-
The connection string for the data source
70+
.PARAMETER AuthenticationType
71+
The type of Authentication for the user for the datasource - SQL or Windows
7472
7573
.PARAMETER ConnectionUserName
7674
The User name for the credential for the datasource if required - Use a
@@ -90,15 +88,14 @@ $ReportServerURI = 'http://localhost/Reports'
9088
$FolderLocation = '/'
9189
$PBIXFile = 'C:\Temp\test.pbix'
9290
$Description = "Descriptions"
93-
$ConnectionString = "Server001;dbachecks"
9491
9592
$publishPBIXFileSplat = @{
9693
ReportServerURI = $ReportServerURI
9794
FolderLocation = $FolderLocation
9895
Description = $Description
9996
PBIXFile = $PBIXFile
100-
ConnectionString = $ConnectionString
10197
FolderName = $FolderName
98+
AuthenticationType = 'Windows'
10299
ConnectionUserName = $UserName1
103100
Secret = $Password1
104101
@@ -108,13 +105,38 @@ $ConnectionString = "Server001;dbachecks"
108105
Deploys a report from the PBIX file C:\Temp\test.pbix to the report server
109106
on the localhost into a folder called TestFolder located at the root of the
110107
server (which it will create if it doesnt exist) and sets the connection
111-
string to "Server001;dbachecks" with a user name and password stored in the
112-
variables
108+
string to use a Windows user name and password stored in the variables
109+
110+
111+
.EXAMPLE
112+
113+
$FolderName = 'TestFolder'
114+
$ReportServerURI = 'http://localhost/Reports'
115+
$FolderLocation = '/'
116+
$PBIXFile = 'C:\Temp\test.pbix'
117+
$Description = "Descriptions"
118+
119+
$publishPBIXFileSplat = @{
120+
ReportServerURI = $ReportServerURI
121+
FolderLocation = $FolderLocation
122+
Description = $Description
123+
PBIXFile = $PBIXFile
124+
FolderName = $FolderName
125+
AuthenticationType = 'SQL'
126+
ConnectionUserName = $UserName1
127+
Secret = $Password1
128+
129+
}
130+
Publish-PBIXFile @publishPBIXFileSplat
131+
132+
Deploys a report from the PBIX file C:\Temp\test.pbix to the report server
133+
on the localhost into a folder called TestFolder located at the root of the
134+
server (which it will create if it doesnt exist) and sets the connection
135+
string to use a SQL user name and password stored in the variables
113136
114137
.NOTES
115138
Rob Sewell 20/08/2018
116139
#>
117-
118140
function Publish-PBIXFile {
119141
[CmdletBinding(DefaultParameterSetName = 'ByUserName', SupportsShouldProcess)]
120142
Param(
@@ -129,7 +151,8 @@ function Publish-PBIXFile {
129151
[Parameter()]
130152
[string]$Description = "Description of Your report Should go here",
131153
[Parameter()]
132-
[string]$ConnectionString,
154+
[ValidateSet('Windows','SQL')]
155+
[string]$AuthenticationType,
133156
[Parameter(ParameterSetName = 'ByUserName')]
134157
[string]$ConnectionUserName,
135158
[Parameter(ParameterSetName = 'ByUserName')]
@@ -196,9 +219,11 @@ function Publish-PBIXFile {
196219

197220

198221
foreach ($dataSource in $datasources) {
199-
if ($ConnectionString) {
200-
# change connection string (to point at new source)
201-
$dataSource.ConnectionString = $ConnectionString
222+
if ($AuthenticationType -eq 'SQL') {
223+
$dataSource.DataModelDataSource.AuthType = 'UsernamePassword'
224+
}
225+
else{
226+
$dataSource.DataModelDataSource.AuthType = 'Windows'
202227
}
203228
if ($Credential -or $UserName) {
204229
if ($Credential) {
@@ -224,4 +249,4 @@ function Publish-PBIXFile {
224249
Return
225250
}
226251
Write-Verbose "Completed Successfully"
227-
}
252+
}

0 commit comments

Comments
 (0)