SSRS哈希表可使用不同的数据源部署多个报告

时间:2019-04-09 20:29:48

标签: reporting-services

我有一个带有报告+数据源的SSRS 2012实例。我有一个Powershell脚本,当前用于部署具有相同数据源的所有报告。

我想将其从单次使用转换为使用不同的报表容器/数据源多次调用的函数。

当我将其从单次使用转换为函数时,我无法解决解决方案所提供的错误。我不知道如何在与哈希表相关的函数中传递变量,这也许就是我出错的地方了。

%:在此对象上找不到属性“名称”。验证该属性存在并且可以设置。 在线:3字符:34 + $ hashTable.GetEnumerator()| %{ + ~~~     + CategoryInfo:InvalidOperation:(:) [ForEach-Object],RuntimeException     + FullyQualifiedErrorId:PropertyAssignmentException,Microsoft.PowerShell.Commands.ForEachObjectCommand

我已经确认,如果不执行任何功能,它将按预期运行。我正在尝试将代码减少为两个DataSource报表的单一用途。

# Print current ErrorActionPrefeence
Write-Output "`$ErrorActionPrefeence is: `"$ErrorActionPreference`""
# set ErrorActionPreference, everything called during a deploy must return 0 or 1 and must fail when it encounters an error
$ErrorActionPreference='stop'
# Print ErrorActionPrefeence once more to demonstrate if it has changed
Write-Output "`$ErrorActionPrefeence is: `"$ErrorActionPreference`""
Write-Output ""

#Create WebServiceProxy
$reportServerUri = "https://server.company.com/reportserver/ReportService2010.asmx?wsdl"
# This property is a "Component Environment Property" and must be set for each environment
#$reportServerUri = "${p:environment/reportServerUri}"
#Write-Output "`$reportServerUri is: `"$reportServerUri`""
Write-Output ""

# myWebServiceProxy is a web service proxy object
$myWebServiceProxy = New-WebServiceProxy -Uri $reportServerUri -UseDefaultCredential -Namespace "SSRS"

#EVAN LOCAL TESTING CONTENT
$myHashTable = @{
    "/company/admin"         = "D:\_Deploy\Reports\Admin";
    "/company/inventory"     = "D:\_Deploy\Reports\Inventory";
    "/company/OEE"           = "D:\_Deploy\Reports\OEE";
    "/company/Preactor"      = "D:\_Deploy\Reports\Preactor";
    "/company/Production"    = "D:\_Deploy\Reports\Production";
    "/company/Receiving"     = "D:\_Deploy\Reports\Receiving";
    "/company/Shipping"      = "D:\_Deploy\Reports\Shipping";
    "/company/Site Specific" = "D:\_Deploy\Reports\Site Specific"
}

$myHashTableLTA = @{
    "/company/Historical"    = "D:\_Deploy\Reports\Historical";
}

$targetDatasourceRef = "/company/Data Source/MES"
$targetDatasourceRefLTA = "/company/Data Source/MES_LTA"

Function reportDeploy {
    Param([hashtable]$hashTable,[string]$dataSource)
    $hashTable.GetEnumerator() | % {
      # Work on this pair in the hash, logical container in SSRS : path in workspace
      $myTempName = $_.Name
      $myTempPath = $_.Value
      Write-Output ""
      #Write-Output "myTempName is: `"$myTempName`" myTempPath is: `"$myTempPath`""
      Write-Output "Report Folder is: `"$myTempName`" myTempPath is: `"$myTempPath`""
      Write-Output "-------------------------------------------------------------"

      # Check that this path exists in this component version's workspace, not
      # all componnent versions will have all of these paths
      if (Test-Path -Path $myTempPath) {
        Write-Output "Working on files found in path: `"$myTempPath`""
          # Get a list of all .rdl files in this path, not all will
          # have files in them (folder change only in Git)
          $rdlFiles = Get-ChildItem -Path $myTempPath -Filter "*.rdl"
          # If count is greater than '0' we will do work
          if ($rdlFiles.Count -gt 0) {
            # loop through .rdl files
            foreach ($rdlfile in $rdlFiles) {

              # null out object that may persist from previous iteration
              $warnings = $null
              $referencedDataSourceName = $null
              # added
              $reportName = $null
              $bytes = $null
              $report = $null

              $reportName = [System.IO.Path]::GetFileNameWithoutExtension($rdlFile.FullName)
              $bytes = [System.IO.File]::ReadAllBytes($rdlFile.FullName)

              Write-Output $("Uploading report ""$reportName"" to " + $myTempName + " ...")
              $report = $myWebServiceProxy.CreateCatalogItem(
                  "Report",         # Catalog item type
                  $reportName,      # Report name
                  $myTempName,      # Destination folder
                  $true,            # Overwrite report if it exists?
                  $bytes,           # .rdl file contents
                  $null,            # Properties to set.
                  [ref]$warnings)   # Warnings that occured while uploading.

              # Confirmed with MNFG folks, warnings are not a show
              # stopper, we will proceed if there are warnings.
              if ($warnings) {
                  $warnings | ForEach-Object {
                    Write-Output "        Warning: Warning encountered calling CreateCatalogItem for: `"$reportName`""
                    #Write-Output "---------------------------------------------------------------------------"
                    Write-Output ("        {0}" -f $_.Message)
                    #Write-Output "---------------------------------------------------------------------------"
                  Write-Output ""
                  }
              } else {
                Write-Output "No warnings encountered calling CreateCatalogItem for: `"$reportName`""
              }

              # Warning outcome reported, proceed
              $referencedDataSourceName = (@($myWebServiceProxy.GetItemReferences($report.Path, "DataSource")))[0].Name
              $dataSource = New-Object SSRS.DataSource
              $dataSource.Name = $referencedDataSourceName      # Name as used when designing the Report
              $dataSource.Item = New-Object SSRS.DataSourceReference
              $dataSource.Item.Reference = $dataSource # Path to the shared data source as it is deployed here.
              $myWebServiceProxy.SetItemDataSources($report.Path, [SSRS.DataSource[]]$dataSource)
              # TODO: print success / failure / exit code of previous line
            }
          } else {
            Write-Output "No `".rdl`" files found in the folder `"$myTempPath`""
          }
        } else {
          Write-Output "Inform: Path not found: `"$myTempPath`", continuing..."
        }
       }
}

reportdeploy -hashTable $myHashTable -dataSource $targetDatasourceRef
#reportdeploy -hashTable $myhashtablelta -dataSource $targetDataSourcrefLTA
Write-Output ""

Goal is to call the function with the hash tables and data sources being provided and have it function without the % : The Property 'Name' error. 

Currently: It connects to SSRS, Starts to deploy reports but if it has multiple reports within a folder it fails before going further with the provided error.

0 个答案:

没有答案