当我刚刚安装了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 -ForceAll done. So simple. I really don't want to think about how many heartbeats of my life I've wasted on this.
更多推荐
发布评论