使用 secedit 启用即时文件初始化的脚本

使用 secedit 启用即时文件初始化的脚本

我希望能够打开 IFIhttp://bit.ly/1dK32Dc在新的或现有的装有 SQL Server 的 Windows Server 机器上,通过 T-SQL 或 Powershell。不想经过“本地安全 > 本地策略 > 用户权限分配 > 执行卷维护任务 > 添加用户”路线 - 需要通过脚本部署新机器,无需手动交互。假设 SQL Server 服务帐户不变。

对于新安装,当我选择帐户时,我可以运行以下 Powershell 脚本并解决问题:

$sqlaccount = "domain\account"
# https://technet.microsoft.com/en-gb/library/bb490997.aspx
secedit /export /cfg C:\secexport.txt /areas USER_RIGHTS
$line = Get-Content C:\secexport.txt | Select-String 'SeManageVolumePrivilege'
(Get-Content C:\secexport.txt).Replace($line,"$line,$sqlaccount") | Out-File C:\secimport.txt
secedit /configure /db secedit.sdb /cfg C:\secimport.txt /overwrite /areas USER_RIGHTS

但是,对于现有的 SQL 安装,无法找到查询已配置的 SQL Server 服务帐户的方法 - 并将其提供给此脚本。正在寻找一种考虑 WS 2012 R2 的解决方案,但最好是在 WS 2003 R2 上也能使用的解决方案(如果我没记错的话,最多支持 Powershell 2?)。

答案1

(Get-WmiObject win32_service | where { $_.displayname -eq "SQL Server"} ).startname

将名称替换为您的 SQL 服务器服务的显示名称

答案2

运行良好,但在 Windows Server 2016 中,它会在 secedit 配置上挂起。为了避免这种情况,只需添加:

写主机 "y" |secedit /configure /db secedit.sdb /cfg C:\secimport.txt /overwrite /areas 用户权限

相关内容