Changing SQL Server Advanced Properties with WMI Provider
2012-03-22 12:32
573 查看
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
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
相关文章推荐
- 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]
- Managing SQL Server Client Aliases with WMI Provider
- Managing SQL Server Services with WMI Provider
- Advanced SQL Server Monitor with Performance Graph, Analysis and Version Control
- SQL Server Configuration Manager – Cannot connect to WMI provider – Invalid class [0x80041010]
- Managing Server Network Protocols with WMI Provider
- Cannot Connect SQLServer 2008 with the provider SQLNCLI
- Advanced SQL Injection In SQL Server Applications
- Login failed for user 'Tester'. Reason: Not associated with a trusted SQL Server connection.
- SQL Server Configuration Manager无法连接WMI的解决方法
- SQLServer With(NoLock)
- Easy Table Partitions with SQL Server 2008(转sql2008表分区)
- provider:命名管道提供程序,error:40 - 无法打开到SQL Server的连接 (Microsoft SQL Server, 错误:53) .
- Microsoft SQL Server 2012 Enterprise Edition with Service Pack 1中文版
- Advanced SQL Injection with MySQL
- The problem of the user is not associated with a trusted sql server connection 混合登录选项设置的问题
- 在 .NET Framework Data Provider for Microsoft SQL Server Compact 3.5 中发生错误
- SparkSQL错误:Could not find uri with key [dfs.encryption.key.provider.uri] to create a keyProvider
- sqlserver group by with cube
- Handling workloads on SQL Server 2008 with Resource Governor