Changing SQL Server Advanced Properties with WMI Provider

原创 2012年03月22日 12:32:06

Suppose the file system is corrupted,in which case you need to restore every database, including the master database. To restore the master database, you need to start the SQL Server in single-user mode. Insert the –m option into the existing startup options, and then restart the database.

The ChangeStartupParameters.ps1 script is shown in the following example. The script first uses the Get-WmiObject cmdlet to instantiate a SqlServiceAdvancedProperty object that corresponds to the STARTUPPARAMETERS property of the default instance. Next, it invokes the SetStringValue method to pre-append the -m option to the string of startup parameters. The ‘‘`n’’ in the script is used to print out the new line character.

# . for the local computer
# If you want to connect to a remote machine, specify the machine name here.
$strComputer='.'
# Name of the targeted service. Here the default SQL Server service is targeted.
# For a named instance INSTANCE1, use "MSSQL`$INSTANCE1"
$strServiceName = "MSSQLSERVER"
$ap=Get-WmiObject -computerName $strComputer –namespace
root\Microsoft\SqlServer\ComputerManagement10 -class SqlServiceAdvancedProperty `
-filter "ServiceName='$strServiceName' and PropertyName='STARTUPPARAMETERS'"
$ap.SetStringValue("-m " + $ap.PropertyStrValue) | Out-Null
# Confirm the "-m" option has been added.
$ap=Get-WmiObject -computerName $strComputer –namespace
root\Microsoft\SqlServer\ComputerManagement10 -class SqlServiceAdvancedProperty `
-filter "ServiceName='$strServiceName' and PropertyName='STARTUPPARAMETERS'"
Write-Host "The startup parameters have been changed to `n" $ap.PropertyStrValue

Note:The new startup option will take effect the next time SQL Server starts.

 

To look at the read-only properties of the SQL Server service:

$strComputer='.'

$strServiceName = "MSSQLSERVER"
$properties=Get-WmiObject -computerName $strComputer –namespace
root\Microsoft\SqlServer\ComputerManagement10 -class SqlServiceAdvancedProperty
-filter "ServiceName=’$strServiceName’"
$properties | Where-Object {$_.IsReadOnly} | Format-table -wrap PropertyName,
PropertyStrValue, PropertyNumValue

相关文章推荐

Managing SQL Server Client Aliases with WMI Provider

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

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

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

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

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

Asp中的MSSQL数据库访问:driver={SQL Server};与Provider = Sqloledb;的区别

Asp中的MSSQL数据库访问:driver={SQL Server};与Provider = Sqloledb;的区别打工作开始(2004年下半年),Asp能见到的两个数据库连接就是driver={...
  • form88
  • form88
  • 2017年03月26日 15:50
  • 302

启动SQL 2005的SQL Server Configuration Manager时显示无法连接到WMI提供程序

我想用sql server做一个数据库的作业,主要是想用一下asp做个网页。首先需要安装sql server,刚开始以为是件很简单的事,在我的visual studio 2008的安装包里就有sql ...

解决SQL Server 2005 登录问题(provider: 共享内存提供程序, error: 0 - 管道的另一端上无任何进程。)

已成功与服务器建立连接,但是在登录过程中发生错误。 (provider: 共享内存提供程序, error: 0 - 管道的另一端上无任何进程。)用户 'sa' 登录失败。该用户与可信 SQL Serv...

(provider: 命名管道提供程序, error: 40 - 无法打开到 SQL Server 的连接) 的解决方案

在与 SQL Server 建立连接时出现与网络相关的或特定于实例的错误。未找到或无法访问服务器。请验证实例名称是否正确并且 SQL Server 已配置为允许远程连接。 (provider: 命名管...

All SQL Server SqlConnection properties(SqlConnection 连接串的所有属性)

原文地址: http://www.connectionstrings.com/all-sql-server-connection-string-keywords/

SQL Server带列名导出到Excel(Export to CSV with headers)的几个思路

SQL Server 2008中SQL应用系列及BI学习笔记系列--目录索引今天在项目中遇到一个问题,需要从SQL Server导出表到Excel,但需要带列名。尝试了几种方法,并小结如下:假定表如下...
  • downmoon
  • downmoon
  • 2012年05月04日 16:33
  • 14256

Remote Data Access Synchronization with SQL Server 2005 Compact Edition and Visual C#.NET

SQL Server 2005 17 out of 26 rated this helpful - Rate this topic   Microsoft Corpora...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Changing SQL Server Advanced Properties with WMI Provider
举报原因:
原因补充:

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