如何使用 ReportService2010 在 PowerShell 中将 SSRS 报告的 Hidden 属性 设置为 "True"?

How do I set a SSRS report's Hidden property to "True" in PowerShell using ReportService2010?

我在这段代码的末尾将隐藏 属性 设置为 "True",但是,它继续显示在报表管理器界面中。有谁知道如何使用 PowerShell 和 ReportService2010 来设置这个 属性?

     $reportServerUri = "http://local/ReportServer_SQL2014/ReportService2010.asmx?wsdl"
     $rs = New-WebServiceProxy -Uri $reportServerUri -UseDefaultCredential 

     $proxyNamespace = $rs.GetType().Namespace

     $targetFolderPath = "/My Reports"
     $targetDatasourceRef = "/SharedDataSources/sdsHP"
     $warnings = $null
     $sourceFolderPath = "C:\Reports"

     Get-ChildItem $sourceFolderPath -Recurse -Filter "*.rdl" | Foreach-Object {
$reportName = [System.IO.Path]::GetFileNameWithoutExtension($_.Name)
$bytes = [System.IO.File]::ReadAllBytes($_.FullName)

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

$warnings | ForEach-Object {
    Write-Output ("Warning: {0}" -f $_.Message)
}

# Set the Hidden property of the reports.
     $report.Hidden = "True" 
     $report.HiddenSpecified = "True"

}         

它更复杂,但对我有用,使用 SMO:

   # Set the Hidden property of subreports using SMO.
    $smodb = New-Object Microsoft.SqlServer.Management.Smo.Database
    $smodb = $smoServer.Databases.Item("ReportServer")
    $smodb.ExecuteNonQuery("UPDATE ReportServer.dbo.Catalog SET Hidden =1 WHERE [Name] = '$ReportName' AND [Type] =2;") 

在报告上传前设置属性:

    $type = $rs.GetType().Namespace
    $datatype = ($type + '.Property')

    $HiddenProp = New-Object($datatype)
    $HiddenProp.Name = 'Hidden'
    $HiddenProp.Value = 'true'
    $Properties = @($HiddenProp)

$report = $rs.CreateCatalogItem(
"Report",         # Catalog item type
$reportName,      # Report name
$targetFolderPath,# Destination folder
$true,            # Overwrite report if it exists?
$bytes,           # .rdl file contents
$Properties,      # Properties to set.
[ref]$warnings)   # Warnings that occurred while uploading.

我知道这是旧的,但我今天必须解决这个问题,这里的答案并没有让我得到我想要的。

我使用 RSTools 制作了 Soap 代理并获取了目录项。 如果您还没有安装它 Invoke-Expression (Invoke-WebRequest https://aka.ms/rstools)

Function Get-RSItemProperties
{
    param ( [System.Web.Services.Protocols.SoapHttpClientProtocol]$Proxy,[string]$RsItemPath )
    $server.Proxy.GetProperties($RsItemPath, $null)
}
Function Get-RSItemProperty
{
    param ( [System.Web.Services.Protocols.SoapHttpClientProtocol]$Proxy,[string]$RsItemPath,[string]$PropertyName )
    Get-RSItemProperties -Proxy $Proxy -RsItemPath $RsItemPath | Where-Object { $_.Name -eq $PropertyName }
}
Function Set-RSItemProperty
{
    param([System.Web.Services.Protocols.SoapHttpClientProtocol]$Proxy,[string]$RsItemPath,[Object[]]$Property)
    $PropertyName = $Property.Name
    $PropertyValue = $Property.Value
    try
    {
        Write-Verbose "Updating $RSItemPath $PropertyName Setting Value to $PropertyValue..."
        $Proxy.SetProperties($RsItemPath, $Property)
    }
    catch
    {
        throw (New-Object System.Exception("Exception occurred while $RSItemPath $PropertyName! $($_.Exception.Message)", $_.Exception))
    }
}
Function Set-RSItemHidden
{
    param([System.Web.Services.Protocols.SoapHttpClientProtocol]$Proxy,[string]$RsItemPath,[bool]$Hide=$True)
    $PropertyName = 'Hidden'

    if ( $Hide )
    {
        $Value = 'True'
    }
    else 
    {
        $Value = 'False'
    }

    $Property = Get-RSItemProperty -Proxy $Proxy -RSItemPath $RSItemPath -PropertyName $PropertyName
    $Property.Value = $Value
    Set-RSItemProperty -Proxy $server.Proxy -RsItemPath $RSItem.Path -Property $Property
}

Function Set-RSAllItemsHidden
{
    param([System.Web.Services.Protocols.SoapHttpClientProtocol]$Proxy)
    $UnHiddenItems = Get-RsCatalogItems -Proxy $Proxy -RsFolder / -Recurse | where-Object Hidden -eq $False
    foreach ( $RSItem in $UnHiddenItems)
    {
        Set-RSItemHidden -Proxy $Proxy -RsItemPath $RsItem.Path
    }

}

$Proxy = New-RsWebServiceProxy -ReportServerUri 'https://ReportServerName.YourDomain.com/Reportserver'

Set-RSAllItemsHidden -Proxy $Proxy