AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / dba / 问题 / 22006
Accepted
ob213
ob213
Asked: 2012-08-05 15:59:12 +0800 CST2012-08-05 15:59:12 +0800 CST 2012-08-05 15:59:12 +0800 CST

如何使用 PS 更改 SQL Server 服务帐户

  • 772

SQL Server 在 AD 帐户 SQLAccount1 下运行。如何使其在另一个帐户 SQLAccount2 下运行?如何在 Powershell 下做到这一点?

sql-server-2008-r2 powershell
  • 2 2 个回答
  • 4865 Views

2 个回答

  • Voted
  1. Best Answer
    benRollag
    2012-08-05T16:50:05+08:002012-08-05T16:50:05+08:00
    1. 执行此操作的 GUI 方法是转到 SQL Server 配置管理器。转到 SQL Server 的属性并在“登录”选项卡上更改帐户名称。单击浏览按钮。

    在此处输入图像描述

    然后输入您希望 SQL Server 登录的帐户。单击检查名称,以确保帐户存在。然后在选择用户或组上单击确定,然后在 SQL Server 属性上单击确定。

    在此处输入图像描述

    比重启。

    2.This blog嘿,脚本专家!博客,作者Aaron Nelson - SQLvariant展示了如何在 PowerShell 中执行此操作。

    [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SqlWmiManagement") | out-null
    
    $SMOWmiserver = New-Object ('Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer') "WIN7NetBook" #Suck in the server you want
    
    #These just act as some queries about the SQL Services on the machine you specified.
    $SMOWmiserver.Services | select name, type, ServiceAccount, DisplayName, Properties, StartMode, StartupParameters | Format-Table
    
    #Same information just pivot the data
    $SMOWmiserver.Services | select name, type, ServiceAccount, DisplayName, Properties, StartMode, StartupParameters | Format-List
    
    #Specify the "Name" (from the query above) of the one service whose Service Account you want to change.
    
    $ChangeService=$SMOWmiserver.Services | where {$_.name -eq "MSSQLSERVER"} #Make sure this is what you want changed!
    
    #Check which service you have loaded first
    
    $ChangeService
    
    $UName="DomainName\UserName"
    
    $PWord="YourPassword"
    
    $ChangeService.SetServiceAccount($UName, $PWord)
    
    #Now take a look at it afterwards
    
    $ChangeService
    
    • 0
  2. SQLing4ever
    2022-10-07T12:01:14+08:002022-10-07T12:01:14+08:00

    Microsoft 为 Powershell Desired State Configuration (DSC) 发布了一个 SQL Server 模块,您可以使用它来更改 SQL Server 服务帐户。

    我只用 Powershell 5 对此进行了测试,所以我不知道它与 Powershell Core 的工作情况如何,所以您可能会遇到

    请注意,这将重新启动您的 SQL SERVER。

    # THIS WILL RESTART YOUR SQL SERVER SERVICE
    $credential = Get-Credential -Message 'Provide the username (domain\username) and password for the SQL Server service account to run under';
    
    
    $SqlServiceAccountParams = @{
        ServerName     = 'localhost'
        InstanceName   = 'MSSQLSERVER'
        ServiceType    = 'DatabaseEngine'
        ServiceAccount = $credential
        RestartService = $true
    };
    
    # Required to be able to run the 
    Install-Module 'SqlServerDsc';
    
    $scriptBlock = {
        $ErrorActionPreference = 'stop'; 
        throw "I understand that this will RESTART THE SQL SERVER. Remove this line if you understand that your SQL Server will restart and are ready for the restart."; 
        Invoke-DscResource -Name 'SqlServiceAccount' -ModuleName 'SqlServerDsc' -Method Set -Property $SqlServiceAccountParams;   
    }
    
    invoke-command $scriptBlock
    
    

    Powershell DSC - https://learn.microsoft.com/en-us/powershell/dsc/getting-started/wingettingstarted?view=dsc-1.1

    SQL Server Powershell DSC 模块 - https://github.com/dsccommunity/SqlServerDsc

    • 0

相关问题

  • SQL Server 2008 R2 中的自动收缩、加密和恢复模型属性

  • SQL Server 2008 R2 群集的无人参与安装失败并出现错误 - “路径中有非法字符”。

  • 迁移大型数据库

  • 代理执行的维护计划

  • 随机化表内容并将它们存储回表中

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何查看 Oracle 中的数据库列表?

    • 8 个回答
  • Marko Smith

    mysql innodb_buffer_pool_size 应该有多大?

    • 4 个回答
  • Marko Smith

    列出指定表的所有列

    • 5 个回答
  • Marko Smith

    从 .frm 和 .ibd 文件恢复表?

    • 10 个回答
  • Marko Smith

    如何在不修改我自己的 tnsnames.ora 的情况下使用 sqlplus 连接到位于另一台主机上的 Oracle 数据库

    • 4 个回答
  • Marko Smith

    你如何mysqldump特定的表?

    • 4 个回答
  • Marko Smith

    如何选择每组的第一行?

    • 6 个回答
  • Marko Smith

    使用 psql 列出数据库权限

    • 10 个回答
  • Marko Smith

    如何从 PostgreSQL 中的选择查询中将值插入表中?

    • 4 个回答
  • Marko Smith

    如何使用 psql 列出所有数据库和表?

    • 7 个回答
  • Martin Hope
    Mike Walsh 为什么事务日志不断增长或空间不足? 2012-12-05 18:11:22 +0800 CST
  • Martin Hope
    Stephane Rolland 列出指定表的所有列 2012-08-14 04:44:44 +0800 CST
  • Martin Hope
    haxney MySQL 能否合理地对数十亿行执行查询? 2012-07-03 11:36:13 +0800 CST
  • Martin Hope
    qazwsx 如何监控大型 .sql 文件的导入进度? 2012-05-03 08:54:41 +0800 CST
  • Martin Hope
    markdorison 你如何mysqldump特定的表? 2011-12-17 12:39:37 +0800 CST
  • Martin Hope
    pedrosanta 使用 psql 列出数据库权限 2011-08-04 11:01:21 +0800 CST
  • Martin Hope
    Jonas 如何使用 psql 对 SQL 查询进行计时? 2011-06-04 02:22:54 +0800 CST
  • Martin Hope
    Jonas 如何从 PostgreSQL 中的选择查询中将值插入表中? 2011-05-28 00:33:05 +0800 CST
  • Martin Hope
    Jonas 如何使用 psql 列出所有数据库和表? 2011-02-18 00:45:49 +0800 CST
  • Martin Hope
    bernd_k 什么时候应该使用唯一约束而不是唯一索引? 2011-01-05 02:32:27 +0800 CST

热门标签

sql-server mysql postgresql sql-server-2014 sql-server-2016 oracle sql-server-2008 database-design query-performance sql-server-2017

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve