# make sure the module is installed:
Install-Module -Name ReportingServicesTools

# add computername to trusted hosts list to be able to connect remotely
Set-Item WSMan:\localhost\Client\TrustedHosts -Value "POWERBI"

# view content of the folder
$reportServerUri = ''
$folderName = "/AFH/Align General/Programs"
Get-RsFolderContent -ReportServerUri $reportServerUri -RsFolder $folderName | Format-Table -AutoSize

# Return existing data source information for "GrossBudget" report. If multiple datasources uses for queries - it will return all of them. 
$ReportPortalUri = ""
Get-RsRestItemDataSource -RsItem "/AFH/GrossBudget" -ReportPortalUri $ReportPortalUri

# Get connection string info for "Construction - AY Loss Ratios" report
$ReportPortalUri = ""
Get-RsRestItemDataSource -RsItem "/AFH/Align General/Programs/Construction - AY Loss Ratios" -ReportPortalUri $ReportPortalUri

#----------Change connection string username and passwork in PowerBI reports-------------------

# connect remotely to POWERBI server
Enter-PSSession -ComputerName POWERBI -Credential ssrsserviceaccount
# specify parameters
$ReportPortalUri = ""
$ReportName = '/AFH/Catalytic/Underwriter Reports/Underwriter Production'
$Username = 'catalyticSSRS'
$Password = 'RND1101!'
$ServerName = ''
# grab parameters that are currently exists in a report
$parameters = Get-RsRestItemDataModelParameters $ReportName -ReportPortalUri $ReportPortalUri
# Map to a dictionary to access the parameter values.
$parameterdictionary = @{}
foreach ($parameter in $parameters) { $parameterdictionary.Add($parameter.Name, $parameter); }
# change parameter value. "ServerName" or "datasource" whatever the name of the parameter in PowerBI
$parameterdictionary[“ServerName”].Value = $ServerName
# update parameters that are currentl in a report
Set-RsRestItemDataModelParameters -RsItem $ReportName -ReportPortalUri $ReportPortalUri -DataModelParameters $parameters
# print what changed
# set authentification mode, username and password
$dataSources = Get-RsRestItemDataSource -RsItem $ReportName -ReportPortalUri $ReportPortalUri
$dataSources[0].DataModelDataSource.AuthType = 'UsernamePassword' # UsernamePassword should be used when specifying SQL or Basic Credentials
$dataSources[0].DataModelDataSource.Username = $Username
$dataSources[0].DataModelDataSource.Secret = $Password
Set-RsRestItemDataSource -RsItem $ReportName -RsItemType PowerBIReport -DataSources $datasources
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter