Listing all Data Sources and their Dependencies (reports, items, etc) in SQL Server 2008 R2

后端 未结 3 2082
挽巷
挽巷 2020-12-05 06:55

I am new to SQL Server, and I am sorry if there is an obvious solution to my question but I can\'t seem to find it.

I am looking to generate a report (or list) of al

3条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-05 07:45

    You might also consider using Powershell:

        #************************************************************************************************************************************
    # FileName:     Delete-DataSources.ps1
    # Date:         2015/04/23
    # Author:       Hugh Scott
    #
    # Description:
    # This script finds data sources with no dependencies in SSRS and removes them.
    #
    # Parameters:
    #   $serverBase     - base URL for the server to check (ie, myserver.mydomain.com)
    #   [$WhatIf]       - Option wwitch parameter to prevent actual deleting of objects (will list out reports that need to be deleted)
    #***********************************************************************************************************************************
    [CmdletBinding()]
    Param(
        [Parameter(Mandatory=$true,Position=0)]
        [string]$serverBase,
        [Parameter(Mandatory=$false,Position=1)]
        [switch]$WhatIf
    )
    
    $url = "http://$serverBase/reportserver/ReportService2010.asmx?WSDL"
    $ssrs = New-WebServiceProxy -uri $url -UseDefaultCredential -Namespace "ReportingWebService"
    
    $outFile = ".\DeleteItems_$serverBase.txt"
    
    # Connection to Web Service, grab all data sources
    $items = $ssrs.ListChildren("/", $true) | where-object {$_.typename -eq "DataSource"}
    foreach($item in $items) {
    
        $dependencies = $ssrs.ListDependentItems($item.Path)
        $dependentReports = $dependencies.Count
    
        if($dependencies.Count -eq 0){
            [string]$itemName = $item.Path
            if($WhatIf){
    
                Write-Host "Item $itemName would be deleted."
                Add-Content $outFile "Item $itemName would be deleted."
            } else {
                try {
                    $ssrs.DeleteItem($item.Path)
                    Write-Host "Item $itemName deleted."
                    Add-Content $outFile "Deleted item $itemName ."
                } catch [System.Exception] {
                    $Msg = $_.Exception.Message
                    Write-Host $itemName $Msg
                    Add-Content $itemName $msg
                }
            }
        }
    }
    

提交回复
热议问题