我一直在尝试自动化一堆服务器的某些SQL Server安装后配置设置。任务之一是将数据库文件的默认增长和增长类型从百分比更改为KB / MB。
对于测试,我将只使用一个实例和一个测试数据库。到目前为止,这是我想出的。
$sqlServer = "SQLSVRNM\INSTNM"
#Load SqlServer SMO assembly
[void][Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SMO")
#Connect to the instance using SMO
$smosvr = New-Object Microsoft.SqlServer.Management.Smo.Server $sqlServer
#Filter database, assign db properties to variable
$database = $smosvr.databases | where name -eq "testdb"
#Check database size
$dbsize = $database.size
#Check database name
$name = $database.name
#Get logfile properties
$logfile = $database.logfiles
#Get logfile name
$logfileName = $logfile.filename
#Get file growth val
$logfileGrowth = $logfile.growth
#Get growthtype
$logfileGrowthtype = $logfile.growthtype
#Get logfile size
$logfileSize = $logfile.size
当我使用设置新的增长大小时
$logfile.growth = [double](2.0 * 32.0)
我收到以下错误。
The property 'growth' cannot be found on this object. Verify that the property exists and can be set.
At line:1 char:1
+ $logfile.growth = [double](2.0 * 32.0)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyAssignmentException
但是,如果我在$ logfile上执行get-member,则属性存在。
$logfile | Get-Member -Name Growth*
TypeName: Microsoft.SqlServer.Management.Smo.LogFile
Name MemberType Definition
---- ---------- ----------
Growth Property double Growth {get;set;}
GrowthType Property Microsoft.SqlServer.Management.Smo.FileGrowthType GrowthType {get;set;}
因此,有人可以帮助我了解我在这里可能会缺少什么吗?谢谢!
您代码中的$ logfile是一个集合。即使只有一个,也必须将其拆分以设置属性
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句