WMI:尝试检索“SqlServerAlias”范围时“无效的命名空间”

时间:2010-09-23 15:09:20

标签: wmi

以下代码抛出ManagementException:“Invalid Namespace”。有什么想法吗?

private ManagementClass GetManagementObject()
{
    const String client = @"localhost";
    const String sqlServerAliasScope = @"SqlServerAlias";
    const String aliasScopePart = @"\root\Microsoft\SqlServer\ComputerManagement10";

    ManagementScope scope = new ManagementScope(@"\\" + client + aliasScopePart);
    ManagementClass clientAlias =
        new ManagementClass(scope, new ManagementPath(sqlServerAliasScope), null);
    clientAlias.Get(); // *** THROWS HERE ***

    return clientAlias;
}

这个PS脚本也会失败,如果上面的话,那么应该失败:

Get-WmiObject -namespace root\Microsoft\SqlServer\ComputerManagement10 -class SqlServerAlias

我是否遗漏了安装服务器的任何内容?

2 个答案:

答案 0 :(得分:1)

这对我有用:

Get-WmiObject -computer SERVER -namespace root\Microsoft\SqlServer\ComputerManagement10 -class SqlServerAlias

返回:

__GENUS          : 2

__CLASS          : SqlServerAlias

__SUPERCLASS     :

__DYNASTY        : SqlServerAlias

__RELPATH        : SqlServerAlias.AliasName="SQLALIAS"

__PROPERTY_COUNT : 4

__DERIVATION     : {}

__SERVER         : SERVER

__NAMESPACE      : root\Microsoft\SqlServer\ComputerManagement10

__PATH           : 

\\SERVER\root\Microsoft\SqlServer\ComputerManagement10:SqlServerAlias.AliasName="SQLALIAS"

AliasName        : SQLALIAS

ConnectionString : 7001

ProtocolName     : tcp

ServerName       : SERVER\SQLALIAS

答案 1 :(得分:0)

你正在查询远程服务器吗?

get-wmiobject -computername SERVER -list -namespace "root\Microsoft\SqlServer\ServerEvents\INSTANCE" -Class SQLServerAlias

我可以成功运行(没有无效的命名空间错误),但不会返回任何结果,但我没有配置任何别名。