【问题标题】:Get-WmiObject can't be executed on PowerShell (x86) but on PowerShellGet-WmiObject 不能在 PowerShell (x86) 但在 PowerShell 上执行
【发布时间】:2017-01-26 05:31:38
【问题描述】:

为什么我可以在 PowerShell 上执行以下代码,但不能在同一台计算机上的 PowerShell (x86) 上执行?

Get-WmiObject -Namespace "root\Microsoft\SqlServer\ComputerManagement13" -Class ServerSettingsGeneralFlag -Filter "FlagName='ForceEncryption'"

例外:

在 line:1 char:1
+ 获取 WmiObject -命名空间“root\Microsoft\SqlServer\ComputerManagement ...
    + CategoryInfo : NotSpecified: (:) [Get-WmiObject], FileNotFoundException
    + FullyQualifiedErrorId : System.IO.FileNotFoundException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

【问题讨论】:

  • 我怀疑相应的命名空间或类在 32 位环境中不存在。您可以使用以下内容枚举命名空间:function List-WmiNamespaces {Get-WmiObject -Namespace $args[0] -Class '__namespace' | ForEach-Object {$ns = '{0}\{1}' -f $_.__Namespace, $_.Name; $ns; List-WmiNamespaces $ns}}; List-WmiNamespaces 'root\microsoft',以及命名空间中的类:Get-WmiObject -Namespace 'root\Microsoft\SqlServer' -List | Select-Object -Expand Name
  • 我确实安装了 64 位 SQL Server。但是这两个脚本在 64 位和 32 位 PowerShell 上得到相同的结果。即 "root\Microsoft\SqlServer\ComputerManagement13" 和 ServerSettingsGeneralFlag 都存在。

标签: sql-server powershell filenotfoundexception


【解决方案1】:

正如@AnsgarWiechers 所说,它可能不存在。至于为什么,可能你安装的是 64 位的 SQL Server 而不是 32 位的?

您可能能够解决此问题的一种方法是使用 PowerShell 远程处理。如果启用并配置了 PowerShell 远程处理,您可以从 32 位进程远程访问您自己的计算机,并且您将连接到 64 位实例。因此,您可以运行此代码以从 64 位会话中获取结果。

$result64 = Invoke-Command -ComputerName . -ScriptBlock {
    Get-WmiObject -Namespace "root\Microsoft\SqlServer\ComputerManagement13" -Class ServerSettingsGeneralFlag -Filter "FlagName='ForceEncryption'"
}

【讨论】:

  • 你的脚本对我有用。即使@ansgar-wiechers 脚本得到相同的结果。
猜你喜欢
  • 2020-11-14
  • 2019-06-15
  • 1970-01-01
  • 1970-01-01
  • 2012-08-11
  • 1970-01-01
  • 2013-10-02
  • 2015-11-23
  • 1970-01-01
相关资源
最近更新 更多