Managing SQL Server Services with WMI Provider

原创 2012年03月21日 13:55:24

The WMI Provider for Configuration Management provides access to WMI objects in the root\Microsoft\SqlServer\ComputerManagement namespace for SQL Server 2005,and the root\Microsoft\SqlServer\ComputerManagement10 namespace for SQL Server 2008.

To list all the classes under the namespace:

Get-WmiObject -namespace root\Microsoft\SqlServer\ComputerManagement10 –list | Where-Object {-not ($_.Name -like '___*')}       ////////2008

 

To view a list of available services of SqlService class on your local computer:

Get-WmiObject -namespace root\Microsoft\SqlServer\ComputerManagement10 -class SqlService | Select-Object ServiceName, DisplayName, SQLServiceType, State,ProcessId | Format-Table -wrap

 

To see all the methods that you can apply to the service instances:

Get-WmiObject -namespace root\Microsoft\SqlServer\ComputerManagement10 -class SqlService | Get-Member -MemberType method

 

To change the SQL Server service account from the local system account to a domain account, PowerDomain\SqlService, and then restart the service for the change to take effect:

$strUserName = "PowerDomain\SqlService"
# Password for the PowerDomain\SqlService account
$strPassword= "P@ssw0rd"
$sqlservice = Get-WmiObject –namespace root\Microsoft\SqlServer\ComputerManagement10 -class SqlService –filter "ServiceName=’MSSQLSERVER’"
$sqlservice.SetServiceAccount($strUserName, $strPassword)
$sqlservice.StopService()
$sqlservice.StartService()

To change a named instance called CH0DE1 on a remote computer DEMOPC. You can change the first line of the preceding script as follows:

$sqlservice = Get-WmiObject –computerName DEMOPC –namespace root\Microsoft\SqlServer\ComputerManagement10 -class SqlService –filter "ServiceName=’MSSQL`$CH0DE1’"

 

To change the start mode from manually to automatically,you can run the AutostartSQLServerAgent.ps1 script shown here:

$strComputer = "."
$sqlservice = Get-WmiObject –computerName $strComputer –namespace
root\Microsoft\SqlServer\ComputerManagement10 `
-class SqlService –filter "ServiceName=’SQLSERVERAGENT’"
$sqlservice.SetStartMode(2)

Start Mode      Description
2                     Service is started automatically
3                     Service is started manually
4                     Service is disabled

Managing SQL Server Client Aliases with WMI Provider

SQL Server client aliases make user connections easier, faster, and more convenient. Each alias save...

SQL Server配置管理器无法连接到 WMI 提供程序。您没有权限或者该服务器无法访问

SQL Server配置管理器无法连接到 WMI 提供程序。您没有权限或者该服务器无法访问 。通过一下几种方法应该能够解决,至少数据库能够正常运行。...

sql server2008 无法连接到WMI提供程序

网上有很多人也遇到了这个问题,我站在巨人的肩膀上总结我试过的几个网上解决过这个方法给大家看看。 方法一: 管理员(administrator)没有 network service的权限或者us...

SQL Server配置管理WMI问题

今天在打开数据库的时候,连接不上。一开错误就知道肯定是SQL Server的服务开启,所以自然而然的去SQL Server配置管理中去打开,但是打开配置管理器的时候出现了下面的错误:  ...
  • huo_yun
  • huo_yun
  • 2013年12月18日 22:13
  • 1497
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Managing SQL Server Services with WMI Provider
举报原因:
原因补充:

(最多只允许输入30个字)