function Add-ORBReportDataSources { <# .SYNOPSIS Creates the Necessary ORB DataSources #> [CmdletBinding()] Param( [Parameter(Mandatory=$true)] [Alias("ConnectionString")] [string]$masterConnectionString, [Parameter(Mandatory=$false)] [Alias("ReportServerUrl")] [string]$reportServerEndpoint, [Parameter(Mandatory=$false)] [Alias("FolderName")] [string]$parentFolder, [Parameter(Mandatory=$false)] [Alias("ReportServerUserName")] [string]$reportsUser, [Parameter(Mandatory=$false)] [Alias("ReportServerPassword")] [string]$reportsPassword, [Parameter(Mandatory=$false)] [Alias("Force")] [switch]$forceOverwriteDataSources, [Parameter(Mandatory=$false)] [string]$environmentType ) $logLead = (Get-LogLeadName); if (!(Test-IsWebServer) -and [String]::IsNullOrEmpty($reportServerEndpoint)) { Write-Warning "$logLead : This function can only be automatically executed on a web tier server. To run, call the function with the appropriate parameters." return } try { [xml]$config = Get-ReportServerConfiguration -WarningAction SilentlyContinue if ($null -ne $config) { $reportServerEndpointNode = $config.appSettings.SelectSingleNode("//add[@key=""ReportServer""]/@value") $reportFolderNode = $config.appSettings.SelectSingleNode("//add[@key=""ReportServerPath""]/@value") $reportUserNode = $config.appSettings.SelectSingleNode("//add[@key=""ReportServerUserName""]/@value") $reportPasswordNode = $config.appSettings.SelectSingleNode("//add[@key=""ReportServerPassword""]/@value") $reportEnvironmentType = $config.appSettings.SelectSingleNode("//add[@key=""Environment.Type""]/@value") } if ((($null -eq $reportServerEndpointNode) -or ([String]::IsNullOrEmpty($reportServerEndpointNode.Value))) -and [String]::IsNullOrEmpty($reportServerEndpoint)) { Write-Warning "$logLead : Could not read the value for the ""ReportServer"" appSetting from the machine.config and no report server URL was provided as a parameter. Execution cannot continue." return; } if ((($null -eq $reportFolderNode) -or ([String]::IsNullOrEmpty($reportFolderNode.Value))) -and [String]::IsNullOrEmpty($parentFolder)) { Write-Warning "$logLead : Could not read the value for the ""ReportServerPath"" appSetting from the machine.config and no parent folder name was provided as a parameter. Execution cannot continue." return; } if ((($null -eq $reportUserNode) -or ([String]::IsNullOrEmpty($reportUserNode.Value))) -and [String]::IsNullOrEmpty($reportsUser)) { Write-Warning "$logLead : Could not read the value for the ""ReportServerUserName"" appSetting from the machine.config and no user name was provided as a parameter. Execution cannot continue." return; } if ((($null -eq $reportPasswordNode) -or ([String]::IsNullOrEmpty($reportPasswordNode.Value))) -and [String]::IsNullOrEmpty($reportsPassword)) { Write-Warning "$logLead : Could not read the value for the ""ReportServerPassword"" appSetting from the machine.config and no password was provided as a parameter. Execution cannot continue." return; } if ((($null -eq $reportEnvironmentType) -or ([String]::IsNullOrEmpty($reportEnvironmentType.Value))) -and [String]::IsNullOrEmpty($environmentType)) { Write-Warning "$logLead : Could not read the value for the ""Environment.Type"" appSetting from the machine.config and value was provided as a parameter. Execution cannot continue." return; } $proxyUrlToUse = IsNull $reportServerEndpoint $reportServerEndpointNode.Value $proxy = New-SSRSProxy $proxyUrlToUse $parentFolderToUse = IsNull $parentFolder $reportFolderNode.Value $usernameToUse = IsNull $reportsUser $reportUserNode.Value $passwordToUse = IsNull $reportsPassword $reportPasswordNode.Value $normalizedParentFolder = ("/" + $parentFolderToUse.TrimStart("/").TrimEnd("/")) # Create the AlkamiMaster Data Source, points to the master database $adminDatasourceCheck = $proxy.GetItemType($normalizedParentFolder + "/AlkamiMaster") if ($null -eq $adminDatasourceCheck -or $adminDatasourceCheck -eq "Unknown" -or $forceOverwriteDataSources.IsPresent) { Write-Host ("$logLead : Creating AlkamiMaster DataSource") (New-ReportServerDataSource $proxy "AlkamiMaster" $masterConnectionString $usernameToUse $passwordToUse $normalizedParentFolder -forceOverwriteDataSources:$forceOverwriteDataSources) | Out-Null } else { Write-Warning ("$logLead : The AlkamiMaster DataSource Already Exists in Folder {0}. To overwrite pass the -Force parameter" -f $normalizedParentFolder) } # Create the Alkami Data Source, the connection string is set by the application $clientDatasourceCheck = $proxy.GetItemType($normalizedParentFolder + "/Alkami") if ($null -eq $clientDatasourceCheck -or $clientDatasourceCheck -eq "Unknown" -or $forceOverwriteDataSources.IsPresent) { Write-Host ("$logLead : Creating Alkami DataSource") (New-ReportServerDataSource $proxy "Alkami" "PlaceHolder" $usernameToUse $passwordToUse $normalizedParentFolder -forceOverwriteDataSources:$forceOverwriteDataSources) | Out-Null } else { Write-Warning ("$logLead : The Alkami DataSource Already Exists in Folder {0}. To overwrite pass the -Force parameter" -f $normalizedParentFolder) } # Create the Alkami_EDW Data Source, points to Flux. $fluxDatasourceCheck = $proxy.GetItemType($normalizedParentFolder + "/Alkami_EDW") if ($null -eq $fluxDatasourceCheck -or $fluxDatasourceCheck -eq "Unknown" -or $forceOverwriteDataSources.IsPresent) { Write-Host ("$logLead : Creating Alkami_EDW DataSource") #If $reportEnvironmentType wasn't found in machine.config(or this is an agent), use the param $reportEnvironmentType = IsNull $reportEnvironmentType.Value $environmentType # Determine the Flux connection string. $fluxConnectionStrings = @{ Production = "Data source=FLUXEDW-1;Initial Catalog=Alkami_EDW"; Staging = "Data Source=RC-EDW1;Initial Catalog=Alkami_EDW"; QA = "Data Source=QA-FLUXDB1;Initial Catalog=Alkami_EDW"; Development = "Data Source=DEV-FLUXDB1;Initial Catalog=Alkami_EDW"; } $fluxConnectionString = $fluxConnectionStrings[$reportEnvironmentType] #Create the datasource if (!([String]::IsNullOrEmpty($fluxConnectionString))) { (New-ReportServerDataSource $proxy "Alkami_EDW" $fluxConnectionString $usernameToUse $passwordToUse $normalizedParentFolder -forceOverwriteDataSources:$forceOverwriteDataSources) | Out-Null } else { Write-Warning("$logLead : Flux EDW connection string could not be determined based on Environment.Type: {$reportEnvironmentType} and was not configured.") } } else { Write-Warning ("$logLead : The Alkami_EDW DataSource Already Exists in Folder {0}. To overwrite pass the -Force parameter" -f $normalizedParentFolder) } } finally { if ($DisposeSessions) { if ($null -ne $SSRSProxy) { $SSRSProxy.Dispose() } if ($null -ne $SSRSExecutionProxy) { $SSRSExecutionProxy.Dispose() } } } }