Change MS SQL Reporting service account to built-in “Network Service”

最后都变了- 提交于 2019-12-24 13:57:58

问题


When I have just installed MS SQL Server 2012 Express, then the Reporting Services Configuration Manager's "Service Account" page states that I'm not using a "built-in account" but rather "another account" (and that the used account is NT Service\ReportServer$<MyServerName>). My installation script states that I need to change this to the situation pictured below.

If I manually open the Reporting Services Configuration Manager GUI and select the "Built-in" option, then close and re-open it, that option is still set. However, if I use Powershell to call SetServiceAccount() (from Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer.Service) to set a specific account, then the "Use another account" option remains set in the GUI. This is what I want to avoid.

The challenge: How can I programmatically (via Powershell, or something I can call from PS) toggle this option (as well as specify a given account, unless I can rely on "Network Service" being the default)?


回答1:


So it turns out there is actually some very simple code to do this. My coworker found it, by which arcane magic I do not know.

Here's the code:

# 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

All done. So simple. I really don't want to think about how many heartbeats of my life I've wasted on this.




回答2:


I reused the accepted answer to set a Service Account (using 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

Using a Service Account you can use NTML (default config): https://docs.microsoft.com/en-us/previous-versions/sql/sql-server-2008-r2/cc281253(v=sql.105)

Then SetSPN for Report Server.

eg:

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

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


来源:https://stackoverflow.com/questions/34769856/change-ms-sql-reporting-service-account-to-built-in-network-service

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!