将MS SQL Reporting服务帐户更改为内置“网络服务”(Change MS SQL Reporting service account to built

编程入门 行业动态 更新时间:2024-10-09 09:16:46
将MS SQL Reporting服务帐户更改为内置“网络服务”(Change MS SQL Reporting service account to built-in “Network Service”)

当我刚刚安装了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调用的东西)切换此选项(以及指定给定的帐户,除非我可以依赖“网络服务”作为默认值)?

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)?

最满意答案

事实证明,实际上有一些非常简单的代码可以做到这一点。 我的同事发现了它,我不知道哪种神秘的魔法。

这是代码:

# 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

全做完了。 很简单。 我真的不想想我曾经浪费过多少生命的心跳。

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.

更多推荐

本文发布于:2023-07-30 14:36:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1338814.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:网络服务   帐户   SQL   Reporting   MS

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!