如何使用ReportService2010在PowerShell中将SSRS报告的隐藏属性设置为“True”?

时间:2016-08-17 01:23:52

标签: powershell reporting-services ssrs-2014

我在此代码的末尾将Hidden属性设置为“True”,但是,它仍继续显示在Report Manager界面中。有没有人知道如何使用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"

}         

3 个答案:

答案 0 :(得分:0)

它更复杂,但对我来说,使用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;") 

答案 1 :(得分:0)

在报告上传之前设置属性:

    $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.

答案 2 :(得分:0)

我知道这很旧,但是我今天必须解决这个问题,这里的答案并没有给我我想要的东西。

我使用RSTools制作了Soap Proxy并获取了目录Items。 如果尚未安装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