无法获得ManagedComputer的smo对象

问题描述 投票:3回答:1

我一直在使用MSDN文章Enable or Disable a Server Network Protocol (SQL Server PowerShell),并且在运行中遇到问题:

$uri = "ManagedComputer[@Name='<computer_name>']/ ServerInstance[@Name='MSSQLSERVER']/ServerProtocol[@Name='Np']"

我收到的错误消息是:

Exception calling "GetSmoObject" with "1" argument(s): "Attempt to retrieve data for object failed for ManagedComputer '<computer_name>'."
At line:1 char:24
+ $Np = $wmi.GetSmoObject <<<< ($uri)
    + CategoryInfo           : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId  : DotNetMethodException

我将<computer_name>替换为计算机的名称。我还尝试从命令中省略<computer_name>(我正在尝试配置运行脚本的计算机),并且得到相同的错误,包括在错误中显示正确的<computer_name>。我也尝试过从第一个/开始忽略所有内容,但没有运气。

我尝试使用cmdpowershellsqlps。我以管理员身份登录,所有窗口顶部都显示管理员,因此我认为这意味着我以管理员身份运行命令。

我正在安装了MS Sql Server 2012的Windows Server 2012上运行。

我的长期目标是创建一个实用程序来在新计算机上安装SQL Server,而无需用户交互。

我该如何解决MSDN文章中的代码行问题?

sql-server powershell
1个回答
0
投票

我在powershell脚本的开头包含了这一行:

Import-Module "sqlps" -DisableNamechecking

并返回到显式放入<computer_name>,现在可以使用了。

我认为由于未执行导入模块而出现错误,但是在导入时,我开始将计算机名称留空,并开始出现XPath错误。


0
投票

ComputerName和InstanceName上的引号是解决方案的关键。

© www.soinside.com 2019 - 2024. All rights reserved.