简体   繁体   English

使用 powershell 在 SSRS 中更改凭证检索

[英]Change Credential Retrieval in SSRS with powershell

I want to change SSRS data source credential retrieval from using the following credentials to without any credentials with powershell and script fails.我想使用 powershell 将 SSRS 数据源凭据检索从使用以下凭据更改为不使用任何凭据,并且脚本失败。

I want to change value 'Store' to 'None' according to this article: https://docs.microsoft.com/en-us/dotnet/api/reportservice2010.credentialretrievalenum?view=sqlserver-2016#ReportService2010_CredentialRetrievalEnum_None我想根据这篇文章将值“存储”更改为“无”: https://docs.microsoft.com/en-us/dotnet/api/reportservice2010.credentialretrievalenum?view=sqlserver-2016#ReportService2010_CredentialRetrievalEnum_None

This is my code:这是我的代码:

$uri ='http://ServerName/ReportServer/ReportService2010.asmx?wsdl'

$reporting = New-WebServiceProxy -uri $uri -UseDefaultCredential -namespace "ReportingWebService"
$DataSources = $reporting.ListChildren('/', $true) | Where-Object  {$_.Name -eq "DataSourceName"}   

  foreach($Object in $DataSources) {
   $dataSource =$reporting.GetDataSourceContents($Object.path)
   #$dataSource.CredentialRetrieval="None"
  $dataSource.CredentialRetrieval=[ReportingWebService.CredentialRetrievalEnum]::None
   $reporting.SetDataSourceContents($Object.path,$dataSource)
 }

This is the error:这是错误:

Exception calling "SetDataSourceContents" with "2" argument(s): "The combination of values for the fields UserName and CredentialRetrieval are not valid. ---> Microsoft.ReportingServices.Diagnostics.Utilities.InvalidElementCombinationException: The combination of values for the fields UserName and CredentialRetrieval are not valid."使用“2”参数调用“SetDataSourceContents”的异常:“UserName 和 CredentialRetrieval 字段的值组合无效。---> Microsoft.ReportingServices.Diagnostics.Utilities.InvalidElementCombinationException:字段值的组合UserName 和 CredentialRetrieval 无效。” At line:13 char:4 + $reporting.SetDataSourceContents($Object.path,$dataSource) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo: NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId: SoapException在 line:13 char:4 + $reporting.SetDataSourceContents($Object.path,$dataSource) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo: NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId: SoapException

The issue was that i actually did not change existent credential retrieval settings 'Store' with required Username parameter.问题是我实际上没有使用所需的用户名参数更改现有的凭据检索设置“存储”。 To resolve it i should create new data source definition with new credential retrieval settings and apply it to my data source:要解决它,我应该使用新的凭据检索设置创建新的数据源定义并将其应用于我的数据源:

$uri ='http://servername/ReportServer/ReportService2010.asmx?wsdl'
$reporting = New-WebServiceProxy -uri $uri -UseDefaultCredential
$type=$reporting.GetType().Namespace
$DataSources = $reporting.ListChildren('/', $true) | Where-Object  {$_.Name -eq "Data source name"} 

 foreach($Object in $DataSources) {
   $dataSource =$reporting.GetDataSourceContents($Object.path)
    $dataSourceDefinitionType = ($type + '.DataSourceDefinition');
    $dataSourceDefinition = New-Object ($dataSourceDefinitionType);
    $dataSourceDefinition.Extension = $dataSource.Extension; #get data from existent data source definition
    $dataSourceDefinition.ConnectString = $dataSource.ConnectString #get data from existent data source definition
    $credentialRetrievalDataType = ($type + '.CredentialRetrievalEnum'); 
    $credentialRetrieval = new-object ($credentialRetrievalDataType);
    $credentialRetrieval.value__ = 3;
    $dataSourceDefinition.CredentialRetrieval = $credentialRetrieval;
    $dataSourceDefinition.WindowsCredentials = $dataSource.WindowsCredentials; #get data from existent data source definition
    $dataSourceDefinition.Enabled = $dataSource.Enabled; #get data from existent data source definition
    $dataSourceDefinition.EnabledSpecified = $dataSource.EnabledSpecified; #get data from existent data source definition
    $reporting.SetDataSourceContents($Object.path,$dataSourceDefinition)
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM