【问题标题】:Change MS SQL Reporting service account to built-in "Network Service"将 MS SQL 报告服务帐户更改为内置的“网络服务”
【发布时间】:2016-04-18 14:44:33
【问题描述】:

当我刚刚安装 MS SQL Server 2012 Express 时,Reporting Services 配置管理器的“服务帐户”页面指出我没有使用“内置帐户”而是“另一个帐户”(并且使用的帐户是NT Service\ReportServer$<MyServerName>)。我的安装脚本指出我需要将其更改为下图所示的情况。

如果我手动打开 Reporting Services 配置管理器 GUI 并选择“内置”选项,然后关闭并重新打开它,该选项仍然设置。但是,如果我使用 Powershell 调用 SetServiceAccount()(来自 Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer.Service)来设置特定帐户,那么“使用另一个帐户”选项仍会在 GUI 中设置。这是我想要避免的。

挑战:我如何以编程方式(通过 Powershell 或我可以从 PS 调用的东西)切换此选项(以及指定给定帐户,除非我可以依赖“网络服务”作为默认值)?

【问题讨论】:

  • 可能 Reporting Services 配置管理器是一个 NT 服务。 (建议您仔细检查services.msc)。如果是这样,则存在一个包含帐户名称的注册表值。像HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\<service name>\ObjectName 这样的东西。您可以使用 PS 的内置注册表支持更改该值。
  • 我的意思是相反的——我不想更改正在使用的帐户,我想像图像中那样“切换单选按钮”(它甚至不会需要一个帐户名)。我不需要提供帐户名称,因为没有,但我认为需要调用一个方法或翻转注册表位。
  • 你在说什么?您必须指定一个帐户名称。屏幕截图中的内置帐户(无密码)或具有该帐户密码的本地/域帐户。见herehere
  • 看,我知道我说的是我几乎一无所知的东西,除了我在安装时在 UI 中看到的东西。抱歉,我正在尽力理解这些(对我而言)晦涩难懂的 Windows/SQL 事物。
  • 我建议您浏览服务(例如通过 services.msc)并找到使用网络服务(或任何您想要的)的服务,然后查看注册表以查看定义了哪些值。然后将适用的值放在您的服务上。 (我对配置 SQL 也一无所知 - 这只是基于我对 NT 服务的了解)

标签: sql-server powershell configuration automation


【解决方案1】:

事实证明,实际上有一些非常简单的代码可以做到这一点。我的同事发现了它,我不知道是什么奥术魔法。

代码如下:

# Init
$ns = "root\Microsoft\SqlServer\ReportServer\RS_$sqlInstanceName\v11\Admin"
$RSObject = Get-WmiObject -class "MSReportServer_ConfigurationSetting" -namespace "$ns"
# Set service account
$builtInServiceAccount = "Builtin\NetworkService"
$useBuiltInServiceAccount = $true
$RSObject.SetWindowsServiceIdentity($useBuiltInServiceAccount, $builtInServiceAccount, "") | out-null
# Set virtual directory URLs
$HTTPport = 80
$RSObject.RemoveURL("ReportServerWebService", "http://+:$HTTPport", 1033) | out-null
$RSObject.RemoveURL("ReportManager", "http://+:$HTTPport", 1033) | out-null
$RSObject.SetVirtualDirectory("ReportServerWebService", "ReportServer", 1033) | out-null
$RSObject.SetVirtualDirectory("ReportManager", "Reports", 1033) | out-null
$RSObject.ReserveURL("ReportServerWebService", "http://+:$HTTPport", 1033) | out-null
$RSObject.ReserveURL("ReportManager", "http://+:$HTTPport", 1033) | out-null
# Restart service
$serviceName = $RSObject.ServiceName
Restart-Service -Name $serviceName -Force

全部完成。很简单。我真的不想去想我在这上面浪费了多少生命的心跳。

【讨论】:

    【解决方案2】:

    我重复使用接受的答案来设置服务帐户(使用 SQL 2016):

    $ns = "root\Microsoft\SqlServer\ReportServer\RS_SSRS\v13\Admin"
    $RSObject = Get-WmiObject -class "MSReportServer_ConfigurationSetting" -namespace "$ns"
    # Set service account
    $serviceAccount = "domain\SRV-ACCOUNT"
    $servicePW = "password"
    $useBuiltInServiceAccount = $false
    $RSObject.SetWindowsServiceIdentity($useBuiltInServiceAccount, $serviceAccount, $servicePW) | out-null
    
    $HTTPport = 80
    $RSObject.RemoveURL("ReportServerWebService", "http://+:$HTTPport", 1033) | out-null
    $RSObject.RemoveURL("ReportManager", "http://+:$HTTPport", 1033) | out-null
    $RSObject.SetVirtualDirectory("ReportServerWebService", "ReportServer", 1033) | out-null
    $RSObject.SetVirtualDirectory("ReportManager", "Reports", 1033) | out-null
    $RSObject.ReserveURL("ReportServerWebService", "http://+:$HTTPport", 1033) | out-null
    $RSObject.ReserveURL("ReportManager", "http://+:$HTTPport", 1033) | out-null
    
    $serviceName = $RSObject.ServiceName
    Restart-Service -Name $serviceName -Force
    

    使用服务帐户,您可以使用 NTML(默认配置):https://docs.microsoft.com/en-us/previous-versions/sql/sql-server-2008-r2/cc281253(v=sql.105)

    然后SetSPN 用于报表服务器。

    例如:

    C:\>setspn –F -S HTTP/MachineName domain\SRV-ACCOUNT
    
    C:\>setspn –F -S HTTP/MachineName.domain.com.au domain\SRV-ACCOUNT
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-07-04
      • 1970-01-01
      • 2016-04-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多