【发布时间】: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