You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用ReportingServicesTool导出SSRS报表的PowerShell文件夹命名问题

解决SSRS报表导出时本地文件夹命名异常问题

问题根源

  • Get-RsFolderContent返回的是对象集合,而非纯字符串。直接循环对象却未指定要提取的属性时,PowerShell会调用对象的ToString()方法,输出格式就是@Name=报表名。
  • 使用| ft -HideTableHeaders会将对象转换为格式化文本,这些文本包含多余空格、换行符等无效字符,导致创建的文件夹名异常(看似随机,实际是错误处理格式化文本的结果)。

正确实现步骤

1. 获取SSRS文件夹并创建本地同名目录

# 导入模块
Import-Module ReportingServicesTool

# 配置SSRS服务器地址和本地根目录
$ssrsUri = "http://your-ssrs-server/ReportServer"
$localRoot = "C:\SSRS_Exports"

# 获取SSRS上的所有文件夹(递归可选)
$ssrsFolders = Get-RsFolderContent -ReportServerUri $ssrsUri -Path "/" -Recurse | 
               Where-Object { $_.TypeName -eq "Folder" }

# 循环创建本地文件夹
foreach ($folder in $ssrsFolders) {
    $localFolder = Join-Path -Path $localRoot -ChildPath $folder.Name
    if (-not (Test-Path $localFolder)) {
        New-Item -ItemType Directory -Path $localFolder | Out-Null
    }
}

2. 导出报表到对应本地文件夹

# 获取SSRS上的所有报表(递归可选)
$ssrsReports = Get-RsFolderContent -ReportServerUri $ssrsUri -Path "/" -Recurse | 
               Where-Object { $_.TypeName -eq "Report" }

# 循环导出报表
foreach ($report in $ssrsReports) {
    # 构建本地保存路径:根目录 + 报表在SSRS的路径(替换分隔符) + .rdl后缀
    $localReportPath = Join-Path -Path $localRoot -ChildPath $report.Path.Replace("/", "\")
    $localReportPath += ".rdl"

    # 确保父目录存在
    $parentDir = Split-Path -Path $localReportPath -Parent
    if (-not (Test-Path $parentDir)) {
        New-Item -ItemType Directory -Path $parentDir | Out-Null
    }

    # 执行导出
    Export-RsReport -ReportServerUri $ssrsUri -Path $report.Path -Destination $localReportPath
}

关键注意事项

  • 确保已正确安装并导入ReportingServicesTool模块(可通过Install-Module ReportingServicesTool安装)。
  • 替换$ssrsUri和$localRoot为你的实际服务器地址和本地目录。
  • 若不需要遍历子文件夹,移除-Recurse参数即可。

内容的提问来源于stack exchange,提问作者devexplorer

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.10 22:40:24