Managing SQL Server Services with WMI Provider
2012-03-21 13:55
423 查看
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
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
- Cannot connect to WMI provider.You do not have permission or the server is unreachable.Note that you can only manager SQL Server 2005 and later version with SQL Server Configuration Manager.Invalid namespace [0x8004100e]
- Changing SQL Server Advanced Properties with WMI Provider
- Managing Server Network Protocols with WMI Provider
- SQL Server Configuration Manager – Cannot connect to WMI provider – Invalid class [0x80041010]
- MDX Solutions : with Microsoft SQL Server Analysis Services 2005 and Hyperion Essbase
- Importing Excel data with SQL Server Integration Services and dealing with unicode and non-unicode data issues
- Build Data-Driven Web Services with Updated XML Support for SQL Server 2000
- Using SOAP Interface with the SQL Server Data Services
- Professional SQL Server 2000 Data Warehousing with Analysis Services
- Managing Client Network Protocols with WMI Provider
- Visual Studio 2008 SP1: Sync Services for ADO.Net with SQL Server 2008 Change Tracking (转)
- Working with Report Snapshots in SQL Server Reporting Services Hyperlink
- Cannot Connect SQLServer 2008 with the provider SQLNCLI
- 使用SQL Server Analysis Services数据挖掘的关联规则实现商品推荐功能(七)
- Restore SQL Server database in same SQL server with different name
- Work with XML Data Type in SQL Server 2005 from ADO.NET 2.0
- 使用SQL Server Analysis Services数据挖掘的关联规则实现商品推荐功能(四)
- Trouble shooting:login failed for user 'sa' ,the user is not associated with a trusted SQL Server
- Microsoft SQL Server 2005 界面概览及 WITH 语法实例(图集)