diff --git a/ReportingServicesTools/Functions/Admin/Set-RsDatabaseCredentials.ps1 b/ReportingServicesTools/Functions/Admin/Set-RsDatabaseCredentials.ps1 index 7887d7a6..3b31d09f 100644 --- a/ReportingServicesTools/Functions/Admin/Set-RsDatabaseCredentials.ps1 +++ b/ReportingServicesTools/Functions/Admin/Set-RsDatabaseCredentials.ps1 @@ -6,48 +6,51 @@ function Set-RsDatabaseCredentials <# .SYNOPSIS This script configures the credentials used to connect to the database used by SQL Server Reporting Services. - + .DESCRIPTION This script configures the credentials used to connect to the database used by SQL Server Reporting Services. You must be an admin in RS and SQL Server in order to perform this operation successfully. - + .PARAMETER DatabaseCredentialType Indicate what type of credentials to use when connecting to the database. - + .PARAMETER DatabaseCredential Specify the credentials to use when connecting to the SQL Server. Note: This parameter will be ignored whenever DatabaseCredentialType is set to ServiceAccount! - + .PARAMETER IsRemoteDatabaseServer Specify this parameter when the database server is on a different machine than the machine Reporting Services is on. - + .PARAMETER ReportServerInstance Specify the name of the SQL Server Reporting Services Instance. Use the "Connect-RsReportServer" function to set/update a default value. - + .PARAMETER ReportServerVersion Specify the version of the SQL Server Reporting Services Instance. Use the "Connect-RsReportServer" function to set/update a default value. - + .PARAMETER ComputerName The Report Server to target. Use the "Connect-RsReportServer" function to set/update a default value. - + .PARAMETER Credential Specify the credentials to use when connecting to the Report Server. Use the "Connect-RsReportServer" function to set/update a default value. - + + .PARAMETER QueryTimeout + Specify how many seconds the query will be running before exit by timeout. Default value is 30. + .EXAMPLE Set-RsDatabaseCredentials -DatabaseCredentialType Windows -DatabaseCredential $myCredentials Description ----------- This command will configure Reporting Services to connect to the database using Windows credentials ($myCredentials). - + .EXAMPLE Set-RsDatabaseCredentials -DatabaseCredentialType SQL -DatabaseCredential $sqlCredentials Description ----------- This command will configure Reporting Services to connect to the database using SQL credentials ($sqlCredentials). - + .EXAMPLE Set-RsDatabaseCredentials -DatabaseCredentialType ServiceAccount Description @@ -66,26 +69,29 @@ function Set-RsDatabaseCredentials [switch] $IsRemoteDatabaseServer, - + [Alias('SqlServerInstance')] [string] $ReportServerInstance, - + [Alias('SqlServerVersion')] [Microsoft.ReportingServicesTools.SqlServerVersion] $ReportServerVersion, - + [string] $ComputerName, - + [System.Management.Automation.PSCredential] - $Credential + $Credential, + + [int] + $QueryTimeout = 30 ) - + if ($PSCmdlet.ShouldProcess((Get-ShouldProcessTargetWmi -BoundParameters $PSBoundParameters), "Configure to use $DatabaseCredentialType authentication")) { $rsWmiObject = New-RsConfigurationSettingObjectHelper -BoundParameters $PSBoundParameters - + #region Validating authentication and normalizing credentials $username = '' $password = $null @@ -94,7 +100,7 @@ function Set-RsDatabaseCredentials $username = $rsWmiObject.WindowsServiceIdentityActual $password = '' } - + else { if ($DatabaseCredential -eq $null) @@ -105,10 +111,10 @@ function Set-RsDatabaseCredentials $password = $DatabaseCredential.GetNetworkCredential().Password } #endregion Validating authentication and normalizing credentials - + $databaseName = $rsWmiObject.DatabaseName $databaseServerName = $rsWmiObject.DatabaseServerName - + #region Configuring Database rights # Step 1 - Generate database rights script Write-Verbose "Generating database rights script..." @@ -124,12 +130,12 @@ function Set-RsDatabaseCredentials $SQLscript = $result.Script Write-Verbose "Generating database rights script... Complete!" } - + # Step 2 - Run Database rights script Write-Verbose "Executing database rights script..." try { - Invoke-Sqlcmd -ServerInstance $DatabaseServerName -Query $SQLscript -ErrorAction Stop + Invoke-Sqlcmd -ServerInstance $DatabaseServerName -Query $SQLscript -QueryTimeout $QueryTimeout -ErrorAction Stop } catch { @@ -138,7 +144,7 @@ function Set-RsDatabaseCredentials } Write-Verbose "Executing database rights script... Complete!" #endregion Configuring Database rights - + #region Update Reporting Services database configuration # Step 3 - Update Reporting Services to connect to new database now Write-Verbose "Updating Reporting Services to connect to new database..." diff --git a/ReportingServicesTools/Functions/CatalogItems/Rest/New-RsRestFolder.ps1 b/ReportingServicesTools/Functions/CatalogItems/Rest/New-RsRestFolder.ps1 index 1262007e..bec2a369 100644 --- a/ReportingServicesTools/Functions/CatalogItems/Rest/New-RsRestFolder.ps1 +++ b/ReportingServicesTools/Functions/CatalogItems/Rest/New-RsRestFolder.ps1 @@ -11,7 +11,7 @@ function New-RsRestFolder This script creates a new folder in the Report Server .PARAMETER RsFolder - Specify the location where the folder should be created + Specify the location where the folder should be created .PARAMETER FolderName Specify the name of the the new folder @@ -91,11 +91,11 @@ function New-RsRestFolder if ($Credential -ne $null) { - $response = Invoke-WebRequest -Uri $foldersUri -Method Post -WebSession $WebSession -Body $payloadJson -ContentType "application/json" -Credential $Credential -Verbose:$false + $response = Invoke-WebRequest -Uri $foldersUri -Method Post -WebSession $WebSession -Body ([System.Text.Encoding]::UTF8.GetBytes($payloadJson)) -ContentType "application/json" -Credential $Credential -Verbose:$false } else { - $response = Invoke-WebRequest -Uri $foldersUri -Method Post -WebSession $WebSession -Body $payloadJson -ContentType "application/json" -UseDefaultCredentials -Verbose:$false + $response = Invoke-WebRequest -Uri $foldersUri -Method Post -WebSession $WebSession -Body ([System.Text.Encoding]::UTF8.GetBytes($payloadJson)) -ContentType "application/json" -UseDefaultCredentials -Verbose:$false } Write-Verbose "Folder $TargetFolderPath was created successfully!" diff --git a/ReportingServicesTools/Functions/CatalogItems/Rest/Set-RsRestItemDataSource.ps1 b/ReportingServicesTools/Functions/CatalogItems/Rest/Set-RsRestItemDataSource.ps1 index 285e4396..e80a1d0d 100644 --- a/ReportingServicesTools/Functions/CatalogItems/Rest/Set-RsRestItemDataSource.ps1 +++ b/ReportingServicesTools/Functions/CatalogItems/Rest/Set-RsRestItemDataSource.ps1 @@ -152,7 +152,7 @@ function Set-RsRestItemDataSource { throw "DataModelDataSource.AuthType must be specified: $ds!" } - elseif (($ds.DataModelDataSource.AuthType -LIKE 'Windows' -or + elseif (($ds.DataModelDataSource.AuthType -LIKE 'Windows' -or $ds.DataModelDataSource.AuthType -LIKE 'UsernamePassword' -or $ds.DataModelDataSource.AuthType -LIKE 'Impersonate') -and ($ds.DataModelDataSource.Username -eq $null -or @@ -171,9 +171,9 @@ function Set-RsRestItemDataSource elseif ($ds.DataSourceSubType -eq $null) { # DataSourceType, ConnectionString and CredentialRetrieval must always be specified! - if ($ds.DataSourceType -eq $null -or + if ($ds.DataSourceType -eq $null -or $ds.ConnectionString -eq $null -or - $ds.CredentialRetrieval -eq $null -or + $ds.CredentialRetrieval -eq $null -or !($ds.CredentialRetrieval -LIKE 'Integrated' -or $ds.CredentialRetrieval -LIKE 'Store' -or $ds.CredentialRetrieval -LIKE 'Prompt' -or @@ -183,7 +183,7 @@ function Set-RsRestItemDataSource } elseif ($ds.DataModelDataSource -ne $null) { - # since this is an embedded data source for Paginated Report/Shared data set, + # since this is an embedded data source for Paginated Report/Shared data set, # you should not set any value to DataModelDataSource throw "You cannot specify DataModelDataSource for this datasource: $ds!" } @@ -208,8 +208,8 @@ function Set-RsRestItemDataSource $dataSourcesUri = [String]::Format($dataSourcesUri, $RsItemType + "s", $RsItem) - # Converting $DataSources into array as PowerBIReport(...)/DataSources expects data sources - # to be in an array in the request body. If $DataSources is already an array, this operation + # Converting $DataSources into array as PowerBIReport(...)/DataSources expects data sources + # to be in an array in the request body. If $DataSources is already an array, this operation # combines $DataSources array with an empty array, so result is still an array. $dataSourcesArray = @($DataSources) @@ -235,11 +235,11 @@ function Set-RsRestItemDataSource Write-Verbose "Updating data sources for $($RsItem)..." if ($Credential -ne $null) { - Invoke-WebRequest -Uri $dataSourcesUri -Method $method -Body $payloadJson -ContentType "application/json" -WebSession $WebSession -Credential $Credential -Verbose:$false | Out-Null + Invoke-WebRequest -Uri $dataSourcesUri -Method $method -Body ([System.Text.Encoding]::UTF8.GetBytes($payloadJson)) -ContentType "application/json" -WebSession $WebSession -Credential $Credential -Verbose:$false | Out-Null } else { - Invoke-WebRequest -Uri $dataSourcesUri -Method $method -Body $payloadJson -ContentType "application/json" -WebSession $WebSession -UseDefaultCredentials -Verbose:$false | Out-Null + Invoke-WebRequest -Uri $dataSourcesUri -Method $method -Body ([System.Text.Encoding]::UTF8.GetBytes($payloadJson)) -ContentType "application/json" -WebSession $WebSession -UseDefaultCredentials -Verbose:$false | Out-Null } Write-Verbose "Data sources were updated successfully!" } diff --git a/ReportingServicesTools/Functions/CatalogItems/Rest/Write-RsRestCatalogItem.ps1 b/ReportingServicesTools/Functions/CatalogItems/Rest/Write-RsRestCatalogItem.ps1 index 200b355b..4d446803 100644 --- a/ReportingServicesTools/Functions/CatalogItems/Rest/Write-RsRestCatalogItem.ps1 +++ b/ReportingServicesTools/Functions/CatalogItems/Rest/Write-RsRestCatalogItem.ps1 @@ -39,28 +39,28 @@ function Write-RsRestCatalogItem .EXAMPLE Write-RsRestCatalogItem -Path 'c:\reports\monthlyreport.rdl' -RsFolder '/monthlyreports' - + Description ----------- Uploads the report 'monthlyreport.rdl' to folder '/monthlyreports' using v2.0 REST Endpoint to Report Server located at http://localhost/reports/. .EXAMPLE Write-RsRestCatalogItem -Path 'c:\reports\monthlyreport.rdl' -RsFolder '/monthlyreports' -RestApiVersion 'v1.0' - + Description ----------- Uploads the report 'monthlyreport.rdl' to folder '/monthlyreports' to v1.0 REST Endpoint to Report Server located at http://localhost/reports/. .EXAMPLE Write-RsRestCatalogItem -WebSession $mySession -Path 'c:\reports\monthlyreport.rdl' -RsFolder '/monthlyreports' - + Description ----------- Uploads the report 'monthlyreport.rdl' to folder '/monthlyreports' to v2.0 REST Endpoint to Report Server located at the specified WebSession object. .EXAMPLE Write-RsRestCatalogItem -ReportPortalUri 'http://myserver/reports' -Path 'c:\reports\monthlyreport.rdl' -RsFolder '/monthlyreports' - + Description ----------- Uploads the report 'monthlyreport.rdl' to folder '/monthlyreports' using v2.0 REST Endpoint to Report Server located at http://myserver/reports. @@ -146,13 +146,13 @@ function Write-RsRestCatalogItem $itemPath = "$RsFolder/$itemName" } - Write-Verbose "Reading file content..." + Write-Verbose "Reading file $item content..." if ($itemType -eq 'DataSource') { [xml] $dataSourceXml = Get-Content -Path $EntirePath if ($item.Extension -eq '.rsds') { - if ($dataSourceXml -eq $null -or + if ($dataSourceXml -eq $null -or $dataSourceXml.DataSourceDefinition -eq $null -or $dataSourceXml.DataSourceDefinition.Extension -eq $null -or $dataSourceXml.DataSourceDefinition.ConnectString -eq $null) @@ -167,7 +167,7 @@ function Write-RsRestCatalogItem } elseif ($item.Extension -eq '.rds') { - if ($dataSourceXml -eq $null -or + if ($dataSourceXml -eq $null -or $dataSourceXml.RptDataSource -eq $null -or $dataSourceXml.RptDataSource.Name -eq $null -or $dataSourceXml.RptDataSource.ConnectionProperties -eq $null -or @@ -178,7 +178,7 @@ function Write-RsRestCatalogItem } $itemName = $dataSourceXml.RptDataSource.Name - $itemPath = $itemPath.Substring(0, $itemPath.LastIndexOf('/') + 1) + $itemName + $itemPath = $itemPath.Substring(0, $itemPath.LastIndexOf('/') + 1) + $itemName $enabled = $true $connectionProperties = $dataSourceXml.RptDataSource.ConnectionProperties $connectionString = $connectionProperties.ConnectString @@ -245,11 +245,11 @@ function Write-RsRestCatalogItem if ($Credential -ne $null) { - Invoke-WebRequest -Uri $catalogItemsUri -Method Post -WebSession $WebSession -Body $payloadJson -ContentType "application/json" -Credential $Credential -Verbose:$false | Out-Null + Invoke-WebRequest -Uri $catalogItemsUri -Method Post -WebSession $WebSession -Body ([System.Text.Encoding]::UTF8.GetBytes($payloadJson)) -ContentType "application/json" -Credential $Credential -Verbose:$false | Out-Null } else { - Invoke-WebRequest -Uri $catalogItemsUri -Method Post -WebSession $WebSession -Body $payloadJson -ContentType "application/json" -UseDefaultCredentials -Verbose:$false | Out-Null + Invoke-WebRequest -Uri $catalogItemsUri -Method Post -WebSession $WebSession -Body ([System.Text.Encoding]::UTF8.GetBytes($payloadJson)) -ContentType "application/json" -UseDefaultCredentials -Verbose:$false | Out-Null } Write-Verbose "$EntirePath was uploaded to $RsFolder successfully!" @@ -279,22 +279,23 @@ function Write-RsRestCatalogItem $uri = [String]::Format($catalogItemsUpdateUri, $itemId) if ($Credential -ne $null) { - Invoke-WebRequest -Uri $uri -Method Put -WebSession $WebSession -Body $payloadJson -ContentType "application/json" -Credential $Credential -Verbose:$false | Out-Null + Invoke-WebRequest -Uri $uri -Method Put -WebSession $WebSession -Body ([System.Text.Encoding]::UTF8.GetBytes($payloadJson)) -ContentType "application/json" -Credential $Credential -Verbose:$false | Out-Null } else { - Invoke-WebRequest -Uri $uri -Method Put -WebSession $WebSession -Body $payloadJson -ContentType "application/json" -UseDefaultCredentials -Verbose:$false | Out-Null + Invoke-WebRequest -Uri $uri -Method Put -WebSession $WebSession -Body ([System.Text.Encoding]::UTF8.GetBytes($payloadJson)) -ContentType "application/json" -UseDefaultCredentials -Verbose:$false | Out-Null } Write-Verbose "$EntirePath was uploaded to $RsFolder successfully!" } catch { - throw (New-Object System.Exception("Failed to create catalog item: $($_.Exception.Message)", $_.Exception)) + Write-Error (New-Object System.Exception("Failed to create catalog item: $($_.Exception.Message)", $_.Exception)) } - return } - - throw (New-Object System.Exception("Failed to create catalog item: $($_.Exception.Message)", $_.Exception)) + else + { + Wrote-Error (New-Object System.Exception("Failed to create catalog item: $($_.Exception.Message)", $_.Exception)) + } } } } diff --git a/ReportingServicesTools/Functions/CatalogItems/Write-RsFolderContent.ps1 b/ReportingServicesTools/Functions/CatalogItems/Write-RsFolderContent.ps1 index 1decdbe7..e9ba842a 100644 --- a/ReportingServicesTools/Functions/CatalogItems/Write-RsFolderContent.ps1 +++ b/ReportingServicesTools/Functions/CatalogItems/Write-RsFolderContent.ps1 @@ -48,11 +48,11 @@ function Write-RsFolderContent param( [switch] $Recurse, - + [Parameter(Mandatory = $True)] [string] $Path, - + [Alias('DestinationFolder')] [Parameter(Mandatory = $True)] [string] @@ -61,27 +61,27 @@ function Write-RsFolderContent [Alias('Override')] [switch] $Overwrite, - + [string] $ReportServerUri, - + [Alias('ReportServerCredentials')] [System.Management.Automation.PSCredential] $Credential, - + $Proxy ) - + if ($PSCmdlet.ShouldProcess($Path, "Upload all contents in folder $(if ($Recurse) { "and subfolders " })to $RsFolder")) { $Proxy = New-RsWebServiceProxyHelper -BoundParameters $PSBoundParameters - + if(-not (Test-Path $Path -PathType Container)) { throw "$Path is not a folder" } $sourceFolder = Get-Item $Path - + if ($Recurse) { $items = Get-ChildItem $Path -Recurse @@ -105,12 +105,13 @@ function Write-RsFolderContent { $parentFolder = $RsFolder + $relativePath } - + #replace possible double slash + $itemToUpload = ("$parentFolder/$($item.Name)") -replace "//", "/" try { - if ($Proxy.GetItemType("$parentFolder/$($item.Name)") -ne "Folder" ) + if ($Proxy.GetItemType($itemToUpload) -ne "Folder" ) { - Write-Verbose "Creating folder $parentFolder/$($item.Name)" + Write-Verbose "Creating folder $itemToUpload" $Proxy.CreateFolder($item.Name, $parentFolder, $null) | Out-Null } else @@ -144,7 +145,7 @@ function Write-RsFolderContent { $parentFolder = $RsFolder + $relativePath } - + try { Write-RsCatalogItem -proxy $Proxy -Path $item.FullName -RsFolder $parentFolder -Overwrite:$Overwrite -ErrorAction Stop diff --git a/ReportingServicesTools/Functions/Security/Grant-RsCatalogItemRole.ps1 b/ReportingServicesTools/Functions/Security/Grant-RsCatalogItemRole.ps1 index 5d4918d9..8c02931e 100644 --- a/ReportingServicesTools/Functions/Security/Grant-RsCatalogItemRole.ps1 +++ b/ReportingServicesTools/Functions/Security/Grant-RsCatalogItemRole.ps1 @@ -126,11 +126,11 @@ function Grant-RsCatalogItemRole { if ($Strict) { - throw "$($Identity) already has $($RoleName) privileges" + throw "$($Identity) already has $($RoleName) privileges on $Path" } else { - Write-Warning "$($Identity) already has $($RoleName) privileges" + Write-Warning "$($Identity) already has $($RoleName) privileges on $Path" return } }