使用Powershell更改SSRS中的凭据检索

我想将SSRS数据源凭据检索从使用以下凭据更改为没有任何Powershell和脚本失败的凭据。

我想根据本文将值“ Store”更改为“ None”: https://docs.microsoft.com/en-us/dotnet/api/reportservice2010.credentialretrievalenum?view=sqlserver-2016#ReportService2010_CredentialRetrievalEnum_None

这是我的代码:

$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)
 }

这是错误:

  

使用“ 2”作为参数调用“ SetDataSourceContents”的异常:“ username和CredentialRetrieval字段的值组合无效。--->   microsoft.ReportingServices.Diagnostics.Utilities.InvalidElementCombinationException:username和CredentialRetrieval字段的值组合无效。”   在线:13字符:4   + $ reporting.SetDataSourceContents($ Object.path,$ dataSource)   + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~       + CategoryInfo:未指定:(:) [],MethodinvocationException       + FullyQualifiedErrorId:SoapException

qinjilei 回答:使用Powershell更改SSRS中的凭据检索

问题是我实际上并没有使用必需的Username参数更改现有的凭据检索设置“存储”。 要解决此问题,我应该使用新的凭据检索设置创建新的数据源定义,并将其应用于我的数据源:

$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)
  }
本文链接:https://www.f2er.com/3160475.html

大家都在问