SQL Server 2008 R2Reporting Services 以降では、Reporting Services サブスクリプションの所有権をユーザー間でプログラムで譲渡できます。 このトピックでは、サブスクリプションの所有権を変更または一覧表示するために使用できる Windows PowerShell スクリプトをいくつか示します。 各サンプルには、ネイティブ モードと SharePoint モードの両方のサンプル構文が含まれています。 サブスクリプション所有者を変更すると、サブスクリプションは新しい所有者とユーザーのセキュリティ コンテキストで実行されます。レポートの [UserID] フィールドには、新しい所有者の値が表示されます。 PowerShell サンプル呼び出しのオブジェクト モデルの詳細については、次を参照してください。 ChangeSubscriptionOwner
適用対象: Reporting Services ネイティブ モード | Reporting Services SharePoint モード |
このトピックの内容:
スクリプトの使用方法
権限
このセクションでは、ネイティブ モードと SharePoint モードの Reporting Services 向けの各メソッドを使用するのに必要な権限レベルを要約します。 このトピックのスクリプトでは、次の Reporting Services メソッドを使用します。
ReportingService2010.FireEvent メソッドは、特定のサブスクリプションをトリガーして実行するために、最後のスクリプトでのみ使用されます。 そのスクリプトを使用する予定がない場合は、FireEvent メソッドのアクセス許可の要件を無視できます。
ネイティブ モード:
サブスクリプションの一覧表示: ( HYPERLINK "https://technet.microsoft.com/library/microsoft.reportingservices.interfaces.reportoperation.aspx"レポートの ReadSubscription とユーザーがサブスクリプション所有者である) または ReadAnySubscription
サブスクリプションを変更する:ユーザーは、BUILTIN\Administrators グループのメンバーである必要があります。
子を一覧表示する:アイテムに対する ReadProperties
イベントを起動する:GenerateEvents (システム)
SharePoint モード:
サブスクリプションの一覧表示: ManageAlerts OR ( HYPERLINK "https://technet.microsoft.com/library/microsoft.sharepoint.spbasepermissions.aspx"レポートの CreateAlerts。ユーザーはサブスクリプションの所有者であり、サブスクリプションは期限付きサブスクリプションです)。
サブスクリプションを変更する:ManageWeb
子を一覧表示する:ViewListItems
イベントを起動する:ManageWeb
詳細については、「 Reporting Services の役割とタスクを SharePoint グループと権限と比較する」を参照してください。
スクリプトの使用
スクリプトファイル (.ps1) の作成
c:\scriptsという名前のフォルダーを作成します。 別のフォルダーを選択した場合は、コマンド ライン構文ステートメントの例で使用されているフォルダー名を変更します。
各スクリプトに対してテキスト ファイルを作成し、ファイルを c:\scripts フォルダーに保存します。 .ps1 ファイルを作成するときは、各コマンド ライン構文の例の名前を使用します。
管理特権でコマンド プロンプトを開きます。
各例で提供されているサンプルのコマンド ライン構文を使用して、各スクリプト ファイルを実行します。
テスト済みの環境
このトピックのスクリプトは、PowerShell バージョン 3 と次のバージョンの Reporting Services でテストされました。
SQL Server 2014
SQL Server 2012
SQL Server 2008 R2
スクリプト: すべてのサブスクリプションの所有権の一覧表示
このスクリプトはサイト上のすべてのサブスクリプションを一覧表示します。 このスクリプトを使用して、接続をテストしたり、他のスクリプトで使用するレポート パスとサブスクリプション ID を確認したりできます。 これは、サブスクリプションが存在し、誰がサブスクリプションを所有しているのかを監査するだけの便利なスクリプトでもあります。
ネイティブ モードの構文
powershell c:\scripts\ListAll_SSRS_Subscriptions.ps1 "[server]/reportserver" "/"
SharePoint モードの構文
powershell c:\scripts\ListAll_SSRS_Subscriptions.ps1 "[server]/_vti_bin/reportserver" "http://[server]"
スクリプト
# Parameters
# server - server and instance name (e.g. myserver/reportserver or myserver/reportserver_db2)
Param(
[string]$server,
[string]$site
)
$rs2010 += New-WebServiceProxy -Uri "http://$server/ReportService2010.asmx" -Namespace SSRS.ReportingService2010 -UseDefaultCredential ;
$subscriptions += $rs2010.ListSubscriptions($site); # use "/" for default native mode site
Write-Host " "
Write-Host "----- $server's Subscriptions: "
$subscriptions | select Path, report, Description, Owner, SubscriptionID, lastexecuted, Status
ヒント
SharePoint モードのサイト URLS を検証するには、SharePoint コマンドレット Get-SPSiteを使用します。 詳細については、「Get-SPSite」を参照してください。
スクリプト: 特定のユーザーが所有するすべてのサブスクリプションの一覧表示
このスクリプトは特定のユーザーが所有するすべてのサブスクリプションを一覧表示します。 このスクリプトを使用して、接続をテストしたり、他のスクリプトで使用するレポート パスとサブスクリプション ID を確認したりできます。 このスクリプトは、所有者を変更したり、サブスクリプションを削除したりできるように、組織内のユーザーが退職し、所有しているサブスクリプションを確認する場合に便利です。
ネイティブ モードの構文
powershell c:\scripts\ListAll_SSRS_Subscriptions4User.ps1 "[Domain]\[user]" "[server]/reportserver" "/"
SharePoint モードの構文
powershell c:\scripts\ListAll_SSRS_Subscriptions4User.ps1 "[Domain]\[user]" "[server]/_vti_bin/reportserver" "http://[server]"
スクリプト
# Parameters:
# currentOwner - DOMAIN\USER that owns the subscriptions you wish to change
# server - server and instance name (e.g. myserver/reportserver or myserver/reportserver_db2)
# site - use "/" for default native mode site
Param(
[string]$currentOwner,
[string]$server,
[string]$site
)
$rs2010 = New-WebServiceProxy -Uri "http://$server/ReportService2010.asmx" -Namespace SSRS.ReportingService2010 -UseDefaultCredential ;
$subscriptions += $rs2010.ListSubscriptions($site);
Write-Host " "
Write-Host " "
Write-Host "----- $currentOwner's Subscriptions: "
$subscriptions | select Path, report, Description, Owner, SubscriptionID, lastexecuted,Status | where {$_.owner -eq $currentOwner}
スクリプト: 特定のユーザーが所有するすべてのサブスクリプションの所有権変更
このスクリプトは、特定のユーザーが所有するすべてのサブスクリプションの所有権を新しい所有者のパラメーターに変更します。
ネイティブ モードの構文
powershell c:\scripts\ChangeALL_SSRS_SubscriptionOwner.ps1 "[Domain]\current owner]" "[Domain]\[new owner]" "[server]/reportserver"
SharePoint モードの構文
powershell c:\scripts\ChangeALL_SSRS_SubscriptionOwner.ps1 "[Domain]\{current owner]" "[Domain]\[new owner]" "[server]/_vti_bin/reportserver"
スクリプト
# Parameters:
# currentOwner - DOMAIN\USER that owns the subscriptions you wish to change
# newOwner - DOMAIN\USER that will own the subscriptions you wish to change
# server - server and instance name (e.g. myserver/reportserver, myserver/reportserver_db2, myserver/_vti_bin/reportserver)
Param(
[string]$currentOwner,
[string]$newOwner,
[string]$server
)
$rs2010 = New-WebServiceProxy -Uri "http://$server/ReportService2010.asmx" -Namespace SSRS.ReportingService2010 -UseDefaultCredential ;
$items = $rs2010.ListChildren("/", $true);
$subscriptions = @();
ForEach ($item in $items)
{
if ($item.TypeName -eq "Report")
{
$curRepSubs = $rs2010.ListSubscriptions($item.Path);
ForEach ($curRepSub in $curRepSubs)
{
if ($curRepSub.Owner -eq $currentOwner)
{
$subscriptions += $curRepSub;
}
}
}
}
Write-Host " "
Write-Host " "
Write-Host -foregroundcolor "green" "----- $currentOwner's Subscriptions changing ownership to $newOwner : "
$subscriptions | select SubscriptionID, Owner, Path, Description, Status | format-table -AutoSize
ForEach ($sub in $subscriptions)
{
$rs2010.ChangeSubscriptionOwner($sub.SubscriptionID, $newOwner);
}
$subs2 = @();
ForEach ($item in $items)
{
if ($item.TypeName -eq "Report")
{
$subs2 += $rs2010.ListSubscriptions($item.Path);
}
}
スクリプト: 特定のレポートに関連付けられたすべてのサブスクリプションの一覧表示
このスクリプトは特定のレポートに関連付けられたすべてのサブスクリプションを一覧表示します。 レポート パスの構文は、完全な URL を必要とする異なる SharePoint モードです。 構文の例では、使用されるレポート名は "タイトルのみ" であり、スペースが含まれているため、レポート名を囲む単一引用符が必要です。
ネイティブ モードの構文
powershell c:\scripts\List_SSRS_One_Reports_Subscriptions.ps1 "[server]/reportserver" "'/reports/title only'" "/"
SharePoint モードの構文
powershell c:\scripts\List_SSRS_One_Reports_Subscriptions.ps1 "[server]/_vti_bin/reportserver" "'http://[server]/shared documents/title only.rdl'" "http://[server]"
スクリプト
# Parameters:
# server - server and instance name (e.g. myserver/reportserver or myserver/reportserver_db2)
# reportpath - path to report in the report server, including report name e.g. /reports/test report >> pass in "'/reports/title only'"
# site - use "/" for default native mode site
Param
(
[string]$server,
[string]$reportpath,
[string]$site
)
$rs2010 = New-WebServiceProxy -Uri "http://$server/ReportService2010.asmx" -Namespace SSRS.ReportingService2010 -UseDefaultCredential ;
$subscriptions += $rs2010.ListSubscriptions($site);
Write-Host " "
Write-Host " "
Write-Host "----- $reportpath 's Subscriptions: "
$subscriptions | select Path, report, Description, Owner, SubscriptionID, lastexecuted,Status | where {$_.path -eq $reportpath}
スクリプト: 特定のサブスクリプションの所有権変更
このスクリプトは特定のサブスクリプションの所有権を変更します。 サブスクリプションは、スクリプトに渡す SubscriptionID によって識別されます。 サブスクリプションを一覧表示するスクリプトのいずれかを使用して、正しい SubscriptionID を判別できます。
ネイティブ モードの構文
powershell c:\scripts\Change_SSRS_Owner_One_Subscription.ps1 "[Domain]\[new owner]" "[server]/reportserver" "/" "ac5637a1-9982-4d89-9d69-a72a9c3b3150"
SharePoint モードの構文
powershell c:\scripts\Change_SSRS_Owner_One_Subscription.ps1 "[Domain]\[new owner]" "[server]/_vti_bin/reportserver" "http://[server]" "9660674b-f020-453f-b1e3-d9ba37624519"
スクリプト
# Parameters:
# newOwner - DOMAIN\USER that will own the subscriptions you wish to change
# server - server and instance name (e.g. myserver/reportserver or myserver/reportserver_db2)
# site - use "/" for default native mode site
# subscriptionID - guid for the single subscription to change
Param(
[string]$newOwner,
[string]$server,
[string]$site,
[string]$subscriptionid
)
$rs2010 = New-WebServiceProxy -Uri "http://$server/ReportService2010.asmx" -Namespace SSRS.ReportingService2010 -UseDefaultCredential;
$subscription += $rs2010.ListSubscriptions($site) | where {$_.SubscriptionID -eq $subscriptionid};
Write-Host " "
Write-Host "----- $subscriptionid's Subscription properties: "
$subscription | select Path, report, Description, SubscriptionID, Owner, Status
$rs2010.ChangeSubscriptionOwner($subscription.SubscriptionID, $newOwner)
#refresh the list
$subscription = $rs2010.ListSubscriptions($site) | where {$_.SubscriptionID -eq $subscriptionid}; # use "/" for default native mode site
Write-Host "----- $subscriptionid's Subscription properties: "
$subscription | select Path, report, Description, SubscriptionID, Owner, Status
スクリプト: 単一のサブスクリプションの実行 (起動)
このスクリプトは、FireEvent メソッドを使用して特定のサブスクリプションを実行します。 スクリプトは、サブスクリプションに対して構成されたスケジュールに関係なく、すぐにサブスクリプションを実行します。 EventType は、レポート サーバー構成ファイルで定義されている既知のイベント セットと照合 されますrsreportserver.config スクリプトでは、標準サブスクリプションに次のイベントの種類が使用されます。
<Event>
<Type>TimedSubscription</Type>
</Event>
構成ファイルの詳細については、 RSReportServer 構成ファイルを参照してください。
このスクリプトには遅延ロジック "Start-Sleep -s 6
" が含まれているため、更新された状態が ListSubscription メソッドで使用できるようになるまで、イベントが発生してから時間が発生します。
ネイティブ モードの構文
powershell c:\scripts\FireSubscription.ps1 "[server]/reportserver" $null "70366e82-2d3c-4edd-a216-b97e51e26de9"
SharePoint モードの構文
powershell c:\scripts\FireSubscription.ps1 "[server]/_vti_bin/reportserver" "http://[server]" "c3425c72-580d-423e-805a-41cf9799fd25"
スクリプト
# Parameters
# server - server and instance name (e.g. myserver/reportserver or myserver/reportserver_db2)
# site - use $null for a native mode server
# subscriptionid - subscription guid
Param(
[string]$server,
[string]$site,
[string]$subscriptionid
)
$rs2010 = New-WebServiceProxy -Uri "http://$server/ReportService2010.asmx" -Namespace SSRS.ReportingService2010 -UseDefaultCredential ;
#event type is case sensative to what is in the rsreportserver.config
$rs2010.FireEvent("TimedSubscription",$subscriptionid,$site)
Write-Host " "
Write-Host "----- Subscription ($subscriptionid) status: "
#get list of subscriptions and filter to the specific ID to see the Status and LastExecuted
Start-Sleep -s 6 # slight delay in processing so ListSubscription returns the updated Status and LastExecuted
$subscriptions = $rs2010.ListSubscriptions($site);
$subscriptions | select Status, Path, report, Description, Owner, SubscriptionID, EventType, lastexecuted | where {$_.SubscriptionID -eq $subscriptionid}
こちらもご覧ください
ListSubscriptions ChangeSubscriptionOwner ListChildren FireEvent