无法获取Get-SQLAgent服务器属性

时间:2019-04-19 15:13:55

标签: sql-server powershell

在我测试过的每台服务器上,此命令总是以异常结尾。我不是管理员,但并不表示这是权限问题。应该行吗?我该如何使用它?

Microsoft SQL Server 2012 (SP4) (KB4018073) - 11.0.7001.0 (X64)
>$PSVersionTable.PSVersion.ToString()
5.1.14409.1018
>(Get-Module -Name SqlServer).Version.ToString()
21.1.18068

命令是:

(Get-SqlAgent -ServerInstance DBSERVER02).Properties

...
Name       : MaximumHistoryRows
Value      : -1
Type       : System.Int32
Writable   : True
Readable   : True
Expensive  : False
Dirty      : False
Retrieved  : True
IsNull     : False
Enabled    : False
Required   : False
Attributes : {}

Name       : MaximumJobHistoryRows
Value      : 0
Type       : System.Int32
Writable   : True
Readable   : True
Expensive  : False
Dirty      : False
Retrieved  : True
IsNull     : False
Enabled    : False
Required   : False
Attributes : {}
  

通过集合枚举时发生错误:异常   在执行Transact-SQL语句或批处理时发生。在第1行:   字符数:1   +(Get-SqlAgent -ServerInstance DBSERVER02).properties   + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~       + CategoryInfo:InvalidOperation:(Microsoft.SqlSe ... pertyEnumerator:PropertyEnumerator)[],   RuntimeException       + FullyQualifiedErrorId:BadEnumeration

更新:

看来PropertiesTargetServerGroups是罪魁祸首。

>$a = Get-SqlAgent -ServerInstance DBSERVER02; $a | Get-Member -Type Properties |% { try { $name = $_.name; $a.$name | out-null } catch { $name + " doesn't work: " + $_ } }
Properties doesn't work: An error occurred while enumerating through a collection: An exception occurred while executing a Transact-SQL statement or batch..
TargetServerGroups doesn't work: The following exception occurred while trying to enumerate the collection: "An exception occurred while executing a Transact-SQL statement
or batch.".

0 个答案:

没有答案